Azure SQL is very different than on premise SQL. When an Azure SQL Server gets overloaded or goes down, it will disconnect a number of connections and when you reconnect you will get sent to another SQL Server.
However with TCP connections you don't know if the other end has terminated the connection unless you actually send information down it, which is why this error occurs.
Once your code know the connection is terminated, it establishes a new connection on the next query, which will work just fine.
With Entity Framework 6 you can now deal with Transient Fault Handling with SQL Azure using Entity Framework
In your DBConfiguration class you need to set your SetExecutionStrategy and configure it. Just create a new class in your project and inherit from DbConfiguration.
public class MyConfiguration : DbConfiguration
{
public MyConfiguration()
{
SetExecutionStrategy(
"System.Data.SqlClient",
() => new SqlAzureExecutionStrategy(1, TimeSpan.FromSeconds(30)));
}
}
Full details at Connection Resiliency / Retry Logic (EF6 onwards)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…