2014-06-13 41 views
7

我正在运行带有使用实体框架6访问的SQL Azure数据库的.Net MVC Azure网站。间歇性地(在一千个左右的请求中)出现错误“ System.ComponentModel.Win32Exception:信号灯超时时间已过期”“信号量超时期限已过”SQL Azure

System.Data.SqlClient.SqlException: A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 0 - The semaphore timeout period has expired.) ---> System.ComponentModel.Win32Exception: The semaphore timeout period has expired

人们似乎没有理由也和之前和之后的错误及其与SQL Azure的相互作用是罚款的请求。有没有办法处理或解决这个问题。

回答

10

Azure SQL与前提条件SQL非常不同。当Azure SQL Server过载或宕机时,它将断开多个连接,并且当您重新连接时,您将被发送到另一个SQL Server。

但是,对于TCP连接,您不知道另一端是否已终止连接,除非您实际上向其发送信息,这就是发生此错误的原因。

一旦你的代码知道连接被终止,它会在下一个查询中建立一个新的连接,这将工作得很好。

实体框架6你现在可以通过Transient Fault Handling with SQL Azure using Entity Framework

对付你需要设置你的SetExecutionStrategy并配置您的DBConfiguration类。只需在您的项目中创建一个新类并从DbConfiguration继承。在Connection Resiliency/Retry Logic (EF6 onwards)

4

有一个已知问题,其中一个VIP交换期间出现这种情况,和EF6重试策略不会在这种情况下帮助

public class MyConfiguration : DbConfiguration 
{ 
    public MyConfiguration() 
    { 
     SetExecutionStrategy( 
      "System.Data.SqlClient", 
      () => new SqlAzureExecutionStrategy(1, TimeSpan.FromSeconds(30))); 
    } 
} 

全部细节。

https://social.msdn.microsoft.com/Forums/azure/en-US/5e195f94-d4d2-4c2d-8a4e-7d66b4761510/vip-swap-and-the-semaphore-timeout-period-has-expired-errors?forum=ssdsgetstarted&prof=required