Databases Reference
In-Depth Information
Alternatively, the TFHAB also provides the ExecuteReaderWithRetry method, which sends the specified
connection to the connection using the specified retry policy:
using (var rdr = cmd.ExecuteReaderWithRetry(myretrypolicy))
Retry policies can also be applied and used with the Entity Framework. The following code illustrates how to
apply a defined policy to a LINQ to Entities query:
using (NorthwindEntities dc = new NorthwindEntities())
{
RetryPolicy myPolicy = new RetryPolicy<SqlAzureTransientErrorDetectionStrategy>(3);
Employee e1 = myPolicy.ExecuteAction<Employee>(() =>
(from x in dc.Employees
where x.LastName == "King"
select x).First());
}
The Transient Fault Handling Application Block provides a simple but very necessary mechanism for building
“best practice” fault-tolerant applications. Retry policies are a way to handle transient conditions and things that
happen externally to your application, such as network and internet connectivity or service interruption.
To see this in action, run the app first as-is to ensure it runs properly. Next, set the number of retries in your
policy to 3 and the retry interval to 3 as well. Unplug your network cable and rerun the app. You will notice that the
application does not error immediately; instead, after 9 seconds it will error. Pretty slick.
Summary
We began the chapter with a discussion of the different factors for deploying your application, such as keeping your
application on-premises or hosting your application in Azure. We also covered application deployment from the
database side, providing some ideas and concepts to consider when moving your database to the cloud, such as how
much of your data to move.
We then discussed the different programming approaches for connecting to and querying a SQL Database
instance, providing examples for each method including ADO.NET and ODBC.
Next, we discussed accessing your SQL Database instance through WCF Data Services. With today's strong
emphasis on SOA architecture coming not only from Microsoft, the discussion of WCF Data Services offered a solid
foundation for providing a services layer for your SQL Database instance.
Lastly, we discussed some crucial best practices, such as implementing Reply Policies in your application
that can drastically improve the end-user experience and add the resiliency needed in cloud-based applications.
Along with retry, we also discussed other best practices including connection pooling and using the
SqlConnectionStringBuilder class. An important component to all application development, regardless of whether
the application is cloud-based or not, is the implementation of fault handling and retry logic. This chapter spent
a few pages on retry login because of how critical it is in cloud-based applications. All of these best practices, if
implemented, will help ensure a well-operating application.
 
Search WWH ::




Custom Search