Using Entity Framework with SQL Azure - Reliability
(This is a cross post from http://stackoverflow.com/questions/5860510/using-entity-framework-with-sql-azure-reliability since I have yet to receive any replies there)
I'm writing an application for Windows Azure. I'm using Entity Framework to access SQL Azure. Due to throttling and other mechanisms in SQL Azure, I need to make sure that my code performs retries if an SQL statement has failed. I'm trying to come up with
a solid method to do this.
(In the code below, ObjectSet returns my EFContext.CreateObjectSet())
Let's say I have a function like this:
public Product GetProductFromDB(int productID)
return ObjectSet.Where(item => item.Id = productID).SingleOrDefault();
Now, this function performs no retries and will fail sooner or later in SQL Azure. A naive workaround would be to do something like this:
public Product GetProductFromDB(int productID)
for (int i = 0; i < 3; i++)
try
return ObjectSet.Where(item => item.Id = productID).SingleOrDefault();
catch
Of course, this has several drawbacks. I will retry regardless of SQL failure (retry is waste of time if it's a primary key violation for instance), I will retry immediately without any pause and so on.
My next step was to start using the Transient Fault Handling library from Microsoft. It contains RetryPolicy which allows me to separate the retry logic from the actual querying code:
public Product GetProductFromDB(int productID)
var retryPolicy = new RetryPolicy<SqlAzureTransientErrorDetectionStrategy>(5);
var result = _retryPolicy.ExecuteAction(() =>
return ObjectSet.Where(item => item.Id = productID).SingleOrDefault;
return result;
The latest solution above is described as ahttp://blogs.msdn.com/b/appfabriccat/archive/2010/10/28/best-practices-for-handling-transient-conditions-in-sql-azure-client-applications.aspx Best Practices for Handling Transient Conditions in SQL Azure Client
Application (Advanced Usage Patterns section).
While this is a step forward, I still have to remember to use the RetryPolicy class whenever I want to access the database via Entity Framework. In a team of several persons, this is a thing which is easy to miss. Also, the code above is a bit messy in my
opinion.
What I would like is a way to enforce that retries are always used, all the time. The Transient Fault Handling library contains a class called ReliableSQLConnection but I can't find a way to use this with Entity Framework.
Any good suggestions to this issue?
Maybe some usefull posts
http://blogs.msdn.com/b/appfabriccat/archive/2010/12/11/sql-azure-and-entity-framework-connection-fault-handling.aspx
http://geekswithblogs.net/iupdateable/archive/2009/11/23/sql-azure-and-entity-framework-sessions-from-pdc-2009.aspx
Similar Messages
-
Using Entity Framework with Crystal Master Detail Reporting
My project is a WPF project connected to a SQL Server Compact Edition database. Since Crystal does not support nullable types, I have created classes specifically for the report to consume. This is a simplified version of what I am attempting to do.
For example...
class Band
public string BandName { get; set; }
public string BandCity { get; set; }
public List<BandRecording> RecordingsList { get; set; }
class BandRecording
public string Year { get; set; }
public string Description { get; set; }
In my code behind for this report, I am using Entity Framework to pull the data. Just pulling information for one band...
using (RockEntities re = new RockEntities())
var bandinfo = (from b in re.Band
where b.BandName == "BT"
select new
b.BandName,
b.BandCity,
Recordings = b.Recordings.OrderBy(z => z.Year)
}).FirstOrDefault();
OK, now I start moving to the data to class I have defined...
Band b = new Band();
b.RecordingsList = new List<BandRecording>();
b.BandName = bandinfo.BandName;
b.BandCity = bandinfo.BandCity;
foreach(var Recording in bandinfo.Recordings)
BandRecording br = new BandRecording();
br.Year = Recording.Year;
br.Description = Recording.Description;
b.RecordingsList.Add(br);
Since Crystal Supports IEnumerable, I create a list to hold the main record (although I am only reporting on one band)...
List<Band> lb = new List<Band>();
lb.Add(lb);
ReportDocument rd = new ReportDocument();
rd.Load("BandReport.rpt");
rd.SetDataSource(lb);
I have put the Band info in the Report Header section. This is all working fine. In the details section I would like to put the Band Recording info. I haven't figured out how to do this. I have put the fields in the Details section, but how do I tell the details section to use the inner List<BandRecordings>?
Any help would be greatly appreciated.Only way I can see of doing this would be to place emprty formulas into the section. The populate the formula(s) with the required field;
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Public Class Form1
Inherits System.Windows.Forms.Form
Dim Report As New CrystalReport1()
Dim FormulaFields As FormulaFieldDefinitions
Dim FormulaField As FormulaFieldDefinition
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
FormulaFields = Report.DataDefinition.FormulaFields
FormulaField = FormulaFields.Item(0)
FormulaField.Text = "[formula text]"
CrystalReportViewer1.ReportSource = Report
End Sub
Ludek
Follow us on Twitter http://twitter.com/SAPCRNetSup
Got Enhancement ideas? Try the [SAP Idea Place|https://ideas.sap.com/community/products_and_solutions/crystalreports] -
Self Reference Model Class - How to populate using Entity Framework
Hi,i have table in SQL Server named Employees as follows:
EmployeeId lastName FirstName reportsTo
1 Davolio Nancy 2
2 Fuller Andrew NULL
3 Leverling Janet 2
4 Peacock Margaret 2
5 Buchanan Steven 2
6 Suyama Michael 5
7 King Robert 5
8 Callahan Laura 2
9 Dodsworth Anne 5
I would like to use Entity Framework to populate my Model Class .My model class looks as follows:
public class Employees
readonly List<Employees> _children = new List<Employees>();
public IList<Employees> Children
get { return _children; }
public string FirstName { get; set; }
public string LastName {get; set;}
I want to use this class in ViewModel to populate my TreeView control. Can anyone help me in order to define Linq to Entities in order to populate my model class Employees from table in SQL Server as defined. Thanks in advance.
AlmirHello Fred,
unfortunately it does not work, maybe I can be more specific about what I'm trying to get. I'm following Josh Smith's article on CodeProject related to WFP TreeView
Josh Smith article. He has Class named Person with the following structure
public class Person
readonly List<Person> _children = new List<Person>();
public List<Person> Children
get
return _children;
public string Name { get; set; }
The same is populated from Database class using method named GetFamilyTree() which look as follows:
public static Person GetFamilyTree()
// In a real app this method would access a database.
return new Person
Name = "David Weatherbeam",
Children =
new Person
Name="Alberto Weatherbeam",
Children=
new Person
Name="Zena Hairmonger",
Children=
new Person
Name="Sarah Applifunk",
new Person
Name="Jenny van Machoqueen",
Children=
new Person
Name="Nick van Machoqueen",
new Person
Name="Matilda Porcupinicus",
new Person
Name="Bronco van Machoqueen",
new Person
Name="Komrade Winkleford",
Children=
new Person
Name="Maurice Winkleford",
Children=
new Person
Name="Divinity W. Llamafoot",
new Person
Name="Komrade Winkleford, Jr.",
Children=
new Person
Name="Saratoga Z. Crankentoe",
new Person
Name="Excaliber Winkleford",
I'm trying to figure out how should I write
GetFamilyTree() method using Entity Framework in order to connect to my SQL Server database and populate this Person class as it was populated manually in Joshs Example. The table I'm using in SQL Server is described in
my first post named Employees (it's self reference table) -
MVC 4 Using Entity Framework How to save Images in Database
Iam Beginner to
MVC 4 ... I want to Upload Image from my form and save to the SQL Database by Using Entity Framework . I have searched alot but couldnt succeed yet,,http://forums.asp.net/
You should post to the MVC section of above forum first. -
Unable to Update .mdf using Entity Framework
I am trying to insert Data in an .mdf file using Entity Framework but there is no data saved in the database. (I am using VS 2013)
Code against the button is
private void BtnSubmit_Click(object sender, RoutedEventArgs e)
Product record = new Product();
record.ProductName = txtProductName.Text;
AzadIndustryEntities1 Db = new AzadIndustryEntities1();
Db.Products.Add(record);
Db.SaveChanges();
MessageBox.Show("Record Inserted");
samEEMy problem is solved. Going to explain it so that it could help others also.
As the default property of .mdf file Copy to Output Directory is
Copy always so when we debug our program a copy of the .mdf file is copied in the
debug folder which is in the bin folder (Select
Show All Files in Solution Explorer to view the bin folder) so, whatever changes we make in database through
code it is saved in the copied .mdf that is in the debug folder. When we
debug our program again the same steps are performed again and the previous database is
overwritten. To prevent such happening the property of .mdf file mentioned above should be set to
Copy if newer so, if there is any change in the model only then the .mdf will be overwritten
samEE -
Create a web site in Visual Studio - fails with SQL Azure V12
Creation of Microsoft Azure Website failed. <Error xmlns="Microsoft.SqlServer.Management.Framework.Web.Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><Message>The service objective 'Web' specified is invalid.</Message><InnerError
i:nil="true"/><SqlErrorCode>40804</SqlErrorCode><Severity>16</Severity></Error>
I receive this error after connecting to a database using the Preview Edition of SQL Azure V12 with a service level of 'Basic'
'Web' may need to be changed to 'Basic' or 'Standard' depending on the service level. How can I do this?
Regards
DavidHi,
Thanks for posting here.
Upgrading Web and Business Databases
Upgrading Web or Business databases to a new service tier/performance level does not take the database offline. The database will continue to work through the upgrade operation. At the time of the actual transition to the new performance level temporary
dropping of the connections to the database can happen for a very small duration (typically measured in seconds). If an application has transient fault handling for connection terminations then it is sufficient to protect against dropped connections at the
end of the upgrade.
Upgrading a Web or Business database to a new service tier involves the following steps:
Determine service tier based on feature capability
Determine an acceptable performance level based on historical resource usage
Why does existing performance for my Web or Business database map to the higher Premium levels?
Tuning your workload to fit a lower performance level
Upgrade to the new service tier/performance level
Monitor the upgrade to the new service tier/performance level
Monitor the database after the upgrade
Refer:
http://azure.microsoft.com/en-us/documentation/articles/sql-database-upgrade-new-service-tiers/
https://msdn.microsoft.com/en-us/library/azure/dn741336.aspx
Hope this helps you.
Girish Prajwal -
Installing ODAC Entity Framework with oracle express
Hi, I need to develop a .net web app with oracle back end. To setup development env. for oracle I downloaded oracle database express edition 11g 2. and installed it succesfully. after I tried to install this ODAC it throws me a error
"Remove all the spaces from the chosen ORACLE_HOME" help me out to resolve this,
Can I use SQL Developer to connect to Oracle Express. Kindly help me out asap.Hello,
This is by designed in Entity Framework, the view is not designed to be editable by default. If you persist in editing a view, you need to create an editable view, for details, please check this blog:
How to create an updateable view with ADO Entity Framework and with LINQ to SQL
This blog is based on the SQL Server database, however, I notice that you are working with the Oracle database, I am not sure if the Oracle database provider for Entity Framework supports the editable view, I
suggest you could confirm this on the Oracle database forum:
https://community.oracle.com/welcome
Regards.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
Cannot refresh data in Excel Services with SQL Azure databases
I am using Excel Services on a SharePoint Online.
I get my data from a SQL Azure. When i create my Excel repor with Excel 2013 pro I have no problem. So I upload my file on my Sharepoint and try to refresh data.
Connexion : Power Query - RPT_Event_ByEventType
Erreur : Erreur sur site (OnPremise) : Sorry, the data source for this data connection isn't registered for Power BI. Ask your Power BI
admin to register the data source in the Power BI admin center.
I do not understad why I get that error because my data source is on Azure why It told me "OnPremise" ?hi,
>> this button of excel gets just address of web and have button for import it
i test it by rest API project , but doesn't work, do you know how it is work?
Do you mean that you don't know how to get the table? You may input the site address into the address box, and then click go button nearby, select the table you want to import into the Excel. Then click import button.That also works for rest API,
and your rest API should get the data that you want
By the way, this is the forum for discussions about Excel develop(VBA ,customization), better to go to TechNet forum for Excel for Excel features question, so that you could get more professional help.
Best Regards
Lan
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
I have started developing a small application in WPF. Since I am completely new to it, to start with I took a microsoft's sample available at
Microsoft Sample Application and following the pattern of the sampke I have been so far successful in creating four different views for their corresponding
master tables. Unfortunately, I have got stuck up as the sample does not contain pattern for creating ViewModel when there is a many-to-many relationship in the database. In my application, I have the following data structure:
1. Table Advocate(advId, Name)
2. Table Party (partyId, Name)
3 Table Case (caseId, CaseNo)
4. Link Table Petitioner (CaseId, PartyId)
5. Link Table Respondent (CaseId, PartyId)
6. Link Table EngagedAdvocate(CaseId, advId)
7. Link Table EngagedSrAdvocate(CaseId, advId)
In the scenario above, I am a bit confused about how to go forward creating the required ViewModel which would render me to have multiple instances of Petitioners, Respondents, Advocates and SrAdvocates.
Please explain details in step by step manner considering that whatever work I have completed so far is a replica of Microsoft's sample referred above. I would also like to mention that I have developed my application
using VB.net. So please provide solution in vb.net.
After getting many-to-many relationship introduced into my application, it would achieve one level above the sample application and I would like to share with the community so that it could be helpful to many aspiring developers seeking help with MVVM.Hi ArunKhatri,
I would suggest you referring to Magnus's article, it provides an example of how you could display and let the user edit many-to-many relational data from the Entity Framework in a dynamic and data-bound DataGrid control in WPF:
http://social.technet.microsoft.com/wiki/contents/articles/20719.wpf-displaying-and-editing-many-to-many-relational-data-in-a-datagrid.aspx
You can learn how to design the ViewModel and the relationship between the entities.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
Connect BizTalk Server Configuration with Sql Azure - version 2013 R2
Hi,
My data resides on Sql Azure. I need to create BizTalkRuleEngineDb on Sql Azure using Microsoft BizTalk Server Configuration wizard. Subsequently manage rules from Business Rule Composer.
I am unable to connect to Sql Azure from BizTalk Server Configuration application. Without this i could not create BizTalkRuleEngineDb on Sql Azure. I gave the following details:
Database server name: <servername>.database.windows.net,1433
User name: <username>
Password: <pwd>
When i click configure button, a message pops "The database server you specified cannot be reached...."
All i need from BizTalk is to create Business Rules Engine DB on Sql Azure. Then I would like to manage rules using Business
Rule Composer connecting to Sql Azure BizTalkRuleEngineDb.<o:p></o:p>
My business logic will programmatically access BizTalkRuleEngineDb db and execute rules using Microsoft.RuleEngine.dll<o:p></o:p>
Is this a feasible solution? I would like to see your inputs.
Any help is appreciated.
Thanks,
TusharFirst I would suggest you to perform sanity check to confirm if SQL server connectivity is perfect.
1) Verify the MSDTC Settings on both the servers:- It should resemble as below.
2) UDL Test:- Create a new "Text Document"(new notepad file) rename it to ABC.udl, double click and give the SQL server details and Test connection. If this fails it means BizTalk is not at all able to connect with SQL and in this
case BizTalk Application is just a victim of Network connectivity issue.
You can also refer the below article-
Resolving the issues you may face during BizTalk Runtime Configuration
Thanks,
Prashant
Please mark this post accordingly if it answers your query or is helpful. -
Using Interactive Report with SQL query accessing tables via db link
Is there a known issue with using the interactive report in version 3.1.2.00.02 with SQL that is accessing tables via a database link? I get the error 'not all variables bound', I do not get this error when using the standard report for the same SQL?
Thanks,
Edited by: [email protected] on May 26, 2009 2:59 PMVarad,
Good question, failed to check that. In fact there are errors. Dump file c:\oraclexe\app\oracle\admin\xe\bdump\xe_s002_3640.trc
Mon Jun 15 08:48:11 2009
ORACLE V10.2.0.1.0 - Production vsnsta=0
vsnsql=14 vsnxtr=3
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
Windows XP Version V5.1 Service Pack 3
CPU : 2 - type 586, 1 Physical Cores
Process Affinity : 0x00000000
Memory (Avail/Total): Ph:1051M/2038M, Ph+PgF:2273M/3934M, VA:1302M/2047M
Instance name: xe
Redo thread mounted by this instance: 1
Oracle process number: 16
Windows thread id: 3640, image: ORACLE.EXE (S002)
*** ACTION NAME:(PAGE 2) 2009-06-15 08:48:11.743
*** MODULE NAME:(APEX:APPLICATION 112) 2009-06-15 08:48:11.743
*** SERVICE NAME:(SYS$USERS) 2009-06-15 08:48:11.743
*** CLIENT ID:(ADMIN:232384011651572) 2009-06-15 08:48:11.743
*** SESSION ID:(24.931) 2009-06-15 08:48:11.743
*** 2009-06-15 08:48:11.743
ksedmp: internal or fatal error
ORA-07445: exception encountered: core dump [ACCESS_VIOLATION] [_LdiDateFromArray+55] [PC:0x608B04F3] [ADDR:0x0] [UNABLE_TO_WRITE] []
Current SQL statement for this session:
select Stage,Procedure,Stp,FW,Reslt,MSG,date_run
from bi_msg_VW@dwitnm
order by 1
----- PL/SQL Call Stack -----
object line object
handle number name
2FE1EA14 1207 package body SYS.DBMS_SYS_SQL
2FE1F064 328 package body SYS.DBMS_SQL
2ABDC520 5097 package body APEX_030200.WWV_RENDER_REPORT3
2BD5E55C 1538 package body APEX_030200.WWV_FLOW_DISP_PAGE_PLUGS
2BD5E55C 366 package body APEX_030200.WWV_FLOW_DISP_PAGE_PLUGS
335BDA88 11190 package body APEX_030200.WWV_FLOW
2BDBD1C8 255 procedure APEX_030200.F
2AB58D10 30 anonymous block
----- Call Stack Trace -----
I didn't include the call stack, it is too large. Now I'm even more puzzled that the IR would work while a sql report would fail.
Bob -
How to use lexical parameters with Sql Server Stored Procedure?
Hi,
I'm developing a BI Publisher report on a sql server database. I need to execute a stored procedure to dynamically build the query by replacing the lexical parameters with the values of varaibles of the stored procedure. With Oracle stored procedures, I have used data template and had reference the varaiable in SP by prefixing it with '&'.
It doesn't work if I try to do the same thing with SQL server. Is there anyone who has come across the similar situation? Please let me know if anyone has got any ideas...
Thanks in Advance
RagTopLink currently doesn't support multiple ResultSets. Multiple ResultSets support is considered for a future release.
-
Cannot insert null into a Primary Key Column using Entity Framework
I have to insert data into UserPreferences Table which has a primary key. This I am doing with Oracle Entity Framework Provider.
It is unable to do it though i have set the StoreGeneratedPattern = "Identity". But while saving changes it is saying a null error is being inserted into the primary key.I exported the same package to BIDS and ran it but still unable to get the issue. It is running fine.
Also then same package is running fine in other environments.
Thanks
Thats strange
Are you pointing to same databases itself while executing from server?
Please Mark This As Answer if it solved your issue
Please Mark This As Helpful if it helps to solve your issue
Visakh
My MSDN Page
My Personal Blog
My Facebook Page -
Must I use spring Framework with JSF2 and Hibernate?
Hi all,
I'm starting to develop a web portal and I would use JSF2 and Hibernate.
Now I don't know JSF2 so I searched some tutorial.
I found a tutorial on JSF2 that seems very complete but in this tutorial I found a section where the author use Hibernate for the "model section", JSF2 for the "view section" and Spring for the "controller section"!
Now I have a doubt, can I develop a web portal without Spring MVC or I can't develop any controller's component with JSF2?
Thank you for your replies!For Ram, do you mean that JSF2 isn't a MVC framework with your reply?
For Kayaman, the author did some examples how implements some frameworks with JSF2 and he do 3 examples:
1) JSF2 and JDBC;
2) JSF2 and Spring;
3) JSF2, Spring and Hibernate!
However, after this thread, I found a forum in linked to the tutorial and I asked why they use JSF2 and Spring together! Now Im waiting the answer!
For Gimbla2: well, I'm novice on JSF2 but I develop for some years with ADF and JBO framework!
You are right to tell me "On the official sites you can find all informations" but I would know some things from some one that used both frameworks!
Thanks again to all.
Edited by: Filippo Tenaglia on 20-giu-2011 14.16 -
Use of PVKConverter with SQL Server 2012 SP2
I am trying to convert a certificate that was exported from our database server to be used by SQL Server for database encryption. When I run the PVKConverter, not Private Key File (PVK) is generated.
The certificate has Server and Client Authentication as the purposes of the certificate.
What purpose or purposes does the certificate need in order to be able to be used by SQL Server 2012 SP2?
Why doesn't the PVKConverter generate a private key file?
I can use the command makecerts to generate a self signed certificate and have it work with SQL Server database encryption.
Thanks.
DJHi DJ,
Based on my research, SQL Server supports the importing of existing security certificates, specified as a pair of files that are encoded in PVK/DER format. Below Transact-SQL script displays the basic key file format for SQL Server database encryption.
CREATE CERTIFICATE <Certificate name>
FROM FILE = '<PVK/DER format file>.cer'
WITH PRIVATE KEY (FILE = '<PVK/DER format file>.pvk',
DECRYPTION BY PASSWORD = '<Encryption password>');
According to your description, PVKConverter doesn’t generate a private key file. PVKConverter is used to generate PVK/DER encoded security certificates from existing PFX encoded security certificates. Thus, please ensure that your certificate is encoded in
PFX format and make sure you perform all the steps properly as described in the
KB article.
There is also a related blog for your reference.
http://blogs.msdn.com/b/sql_pfe_blog/archive/2014/02/04/generating-a-trusted-tde-certificate-in-the-proper-format-from-a-certificate-authority.aspx
Thanks,
Lydia Zhang
Lydia Zhang
TechNet Community Support
Maybe you are looking for
-
How Do you use Cyrillic Fonts (Russian) in InDesign CS4 or CS3
I have a headline in Russian a client sent me in an e-mail that I need to use on a poster I'm laying out in InDesign. I downloaded ERUniverse cyrillic font, and when I paste the Russian headline in a text box and go to select ERUniverse cyrillic, the
-
Hello guys, I've configured CUCM and IM&P v9.1 and jabber client 9.2(1), the chat works fine and also the Cisco Unified Client Services Framework Device can make and receive calls but if I try to select the desk phone for calls it just keeps trying t
-
Save for web really slooooow in Photoshop CC
Hi all, Since one of the last updates, whenever I try to save an image using the Save for web function, the dialog screens take a lot of time to appear (worked normally before). I am not using large images, just 1100x700 px approximately that I reduc
-
GetURL:: works for all but my client!
I have a two buttons at the end of a movie that should go to next page when clicked. Works great for me on PC with XP or Vista and IE 6 & 7, FF 2 and Netscape 7. Works on Mac OS 10.2 with Safari. Works on my friend's Mac with OS 10.3.9 and IE 5.2. Do
-
Hi, I m trying to configure Customer Dunning and following the following process: Define Dunning Area OB61 Define Dunning Process FBMP Assigning Dunning Process in customer master. I follow the steps mentioned in another poet on SCN but i am unable t