Best Practices for Handling Transient Conditions in SQL Azure Client Applications


This post has been moved to a new location. Please follow the link below. Thank you.

http://windowsazurecat.com/2010/10/best-practices-for-handling-transient-conditions-in-sql-azure-client-applications/

Comments (18)

  1. BT says:

    Great approach.

    Is there a best-practices example as it relates to EF 4.0 Code-First approaches relying on DbContext rather than native EF?

    I guess one question I have is whether it's appropriate to forcibly open the connection before SaveChanges is called, which under EF/CF would normally open the connection and execute the transactionally wrapped commands at the very last moment.  Does it matter?

    Also, is there a best practices way to grab (and wrap) the connection object from a DbContext when using this approach?

  2. Valery M says:

    We are collaborating with the Entity Framework team to be able to provide a consistent story here. We will publish our recommendations in due course.

  3. Peter Kellner says:

    Great code! thanks.  I get the ado.net sample to work, but when i look at your AdventureWorksEntities.cs in the test project, I can't see how the retry logic gets executed when you call things like datacontext.savechanges() (and in my testing, it does not).  Could you show (or tell) where the extension method gets called that will execute the retry logic?  I don't get it from the test project or the article.

  4. Valery M says:

    Peter, thank you for reaching out to us.

    Please note that the test project included into the source code distributed on the MSDN Code Gallery is reserved for internal testing and prototyping purposes and should not ideally be used as implementation guidance. I recommend you to review the following post that specifically talks about retry scenarios with Entity Framework.

    blogs.msdn.com/…/sql-azure-and-entity-framework-connection-fault-handling.aspx

  5. As shown previously it isn’t hard to run Workflow Services on Windows Azure. In fact all we need to do

  6. Will Tartak says:

    There is a dependency on Microsoft.ServiceBus but I don't have that dll in my system, that I know of. It does not show in the references dialog and is not in the Windows Azure 1.3 SDK folders. I searched Microsoft Download and it returned nothing. Where can I get this dll? Or where on my system might I find it?

  7. Will Tartak says:

    Never mind, I found it. It is part of the AppFabric SDK which I did not have installed. In case anyone is looking for it I got it from:

    http://www.microsoft.com/…/details.aspx

  8. Niall says:

    When will MS Patterns & Practices Data Access Block include this type of logic and config?

    Thanks

  9. Valery M says:

    Hi Niall,

    It's a perfectly valid question for the P&P team. We already provided them with all the code artifacts and asked to integrate the retry framework into the DAB. If you look at the work we have done with the EntLib's DAB, you will see that it's not too difficult to implement such integration yourself.

    appfabriccat.com/…/enterprise-library-on-windows-azure-key-learnings-from-customer-project

    Valery

  10. Grigori Melnik (Microsoft patterns & practices) says:

    Niall, perfect timing!

    The EntLib team is currently in the exploration phase for the Windows Azure Integration Pack for Enterprise Library 5.0. Please suggest this as a story on our uservoice site. Other users will be able to vote on this and we'll take that into consideration when finalizing our product backlog.

    Thanks,

    Grigori

    Enterprise Library producer

  11. Grigori Melnik (Microsoft patterns & practices) says:

    Here's the uservoice link: entlib.uservoice.com/…/101257-azure-integration-pack

  12. Thank you so much for making this library!  However I cannot get it to work with SQL Server Express because the connection strings contain (Server=hostnameSQLEXPRESS), and GetDnsSafeConnectionString() tries to look the whole thing up in the DNS.  I can work around this by conditionally only calling OpenWithRetry() when I know it is an SQL Azure database, but is there a better way?

  13. Valery M says:

    Thank you for getting in touch. SQL Server Express is fully supported by our framework. DNS lookups performed by GetDnsSafeConnectionString should not impact your use of SQL Express, although we may be performing DNS lookups against the full instance name which is not ideal. I have modified this behavior so that we handle SQL Express instance names more efficiently. The update has already been put on our MSDN Code Gallery. Please review and let us know if there will any further questions.

  14. Wow, that was fast!  Working perfectly for me now.

  15. I tried this RetryPolicy because I want a robust application.

    I have the following code:

    int MaxRetry = 5;

    int DelayMS = 100;

    policy = new RetryPolicy<SqlAzureTransientErrorDetectionStrategy>(MaxRetry, TimeSpan.FromMilliseconds(DelayMS));

    Type = policy.ExecuteAction<string>(() => context.properties.First(p => p.Name == "not_exist_type_id").Value);

    but it sometiomes throws exception:

    "Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding."  

    The RetryPolicy is not working if the connection times out?

    Best regards,

    Tom

  16. Valery M says:

    Tamás,

    Thanks for reaching out.

    By default, the framework is not configured to handle the timeout errors. We believe that this type of exceptions is not something we will encourage the developers to compensate by a retry. Timeouts may have a very distinct nature and can be the result of poor schema design, lack of indexes, suboptimal query plans, blockings, timeout settings misconfiguration, and more. It is unwise to always retry when you get a timeout.

    Instead, I would recommend looking into the queries being executed and try to determine the reasons behind timeouts. If you are 100% confident that your queries are generating a good execution plan, you have all the right indexes and everything is configured correctly, and you are still seeing timeouts, you have all the source code in your possession. The implementation of the SqlAzureTransientErrorDetectionStrategy class can be easily modified to catch the timeout exceptions. To re-iterate, this is not a general recommendation. We leave the timeout handling at your own discretion.

  17. I cannot find examples for how to use your framework for retrying Azure storage operations.  Any hints?

  18. Valery M says:

    Hi oliverbock,

    We have a plenty of real-world examples of how to use the framework with Windows Azure queues and blobs in order to make storage operations more resilient to transient faults. Specifically, please review the following post and download the sample code.

    windowsazurecat.com/…/implementing-storage-abstraction-layer-to-support-very-large-messages-in-windows-azure-queues

Skip to main content