I will get errors like this below at random points as we are running our app.
Message from elmah:
System.Data.SqlClient.SqlExceptionDatabase '......' on server '........' is not currently available. Please retry the connection later. If the problem persists, contact customer support, and provide them the session tracing ID of '.........'.
Top message in stack trace:
System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.Data.Entity.Core.EntityException: An exception has been raised that is likely due to a transient failure. If you are connecting to a SQL Azure database consider using SqlAzureExecutionStrategy. ---> System.Data.Entity.Core.EntityException: The underlying provider failed on Open. ---> System.Data.Entity.Core.EntityException: An exception has been raised that is likely due to a transient failure. If you are connecting to a SQL Azure database consider using SqlAzureExecutionStrategy. ---> System.Data.SqlClient.SqlException: Database '......' on server '.......' is not currently available. Please retry the connection later. If the problem persists, contact customer support, and provide them the session tracing ID of '......'.
I've dug into this and have created the following class to use the configuration below against my database
public class SqlAzureDBConfiguration : DbConfiguration
{
public SqlAzureDBConfiguration()
{
SetExecutionStrategy("System.Data.SqlClient", () => new SqlAzureExecutionStrategy(10, TimeSpan.FromSeconds(15)));
SetDefaultConnectionFactory(new LocalDbConnectionFactory("v11.0"));
}
}
I've also modified my web.config file to use the configuration.
Since the error is that the server does not exist (and I know that it does), I assume that there is some type of intermittent error that is happening in the azure cloud's internal network between the web server and the database server. The web and db server are setup in the same region. We have had this happen two times during the testing of azure over the last three months.
I am trying to get the connection to retry if it does not first connect. Given that both times we have had this, the error has lasted about a minute, I'd like to retry every 10 seconds for the next 150 seconds just to see if we can connect. Unfortunately, this does not appear to be working properly. When I disconnect from the wireless here at my office, I get an error here after about 15-20 seconds regarding attempting to connect to the sql azure db. It would seem to me that the class SqlAzureExecutionStrategy is going to handle the execution of commands. Am i correct in this? Is there a way to handle transient failed connections? is there something else that I need to do to cause a retry? Any suggestion is appreciated.
Thanks,
Wally