rou*_*uen 5 sql-server entity-framework azure azure-sql-database
我有azure云服务 - 2个Web实例,每天服务大约500,000个请求.使用Azure业务数据库.有一个问题 - 有时(平均每天一次,但不是在同一时间)有2-3分钟的间隔,而我无法查询数据库,错误信息是这样的:
System.Data.Entity.Core.EntityException: The underlying provider failed on Open. ---> System.Data.SqlClient.SqlException: Connection Timeout Expired. The timeout period elapsed during the post-login phase. The connection could have timed out while waiting for server to complete the login process and respond; Or it could have timed out while attempting to create multiple active connections. The duration spent while attempting to connect to this server was - [Pre-Login] initialization=1; handshake=12; [Login] initialization=0; authentication=0; [Post-Login] complete=14004; ---> System.ComponentModel.Win32Exception: The wait operation timed out
--- End of inner exception stack trace ---
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.Open()
at System.Data.Entity.Infrastructure.DbExecutionStrategy.<>c__DisplayClass1.<Execute>b__0()
at System.Data.Entity.Infrastructure.DbExecutionStrategy.Execute[TResult](Func`1 operation)
at System.Data.Entity.Core.EntityClient.EntityConnection.Open()
--- End of inner exception stack trace ---
at System.Data.Entity.Core.EntityClient.EntityConnection.Open()
at System.Data.Entity.Core.Objects.ObjectContext.EnsureConnection()
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClassb.<GetResults>b__9()
at System.Data.Entity.Infrastructure.DbExecutionStrategy.Execute[TResult](Func`1 operation)
at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
at System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0()
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at MyProject.MyRepository.GetItems(Boolean includePremium, Int32 a, Int32 b, Int32 c)
at MyProject.Controllers.MyController.GetItems(String Id, String device)
Run Code Online (Sandbox Code Playgroud)
消息中的数字 - [Pre-Login]初始化= 1; 握手= 12; [登录]初始化= 0; 认证= 0; [登录后]完成= 14004 - 总是一样的,不是一些随机的等待时间或者什么......
当然我试图谷歌这个错误,但我所能找到的只是与普通ADO.NET等错误的连接管理有关.我使用实体框架6,代码优先模型,linq实体查询,查询不重(几毫秒,总是低于1秒).
SO上有这样的问题:SQL Azure中的连接超时有"这是暂时性错误,只是再试一次"这样的答案 - 但这不会解决它,我在这段时间内得到了数百个这样的错误,我很确定每个请求失败,所以"等待5秒再试一次"政策在这里没有帮助.
有关Azure DB的一些特殊内容,我必须对EF中的连接生命周期管理做些什么?或者您认为这可能是"限制"数据库的错误消息?
好吧,经过一段时间和一些重构,看来这个错误确实表明了限制。我们设法减少了每分钟的请求数量,并且在没有任何其他更改的情况下,这些错误完全消失了。
遗憾的是 SQL Azure 没有提供更多有关限制/资源的有用消息。
| 归档时间: |
|
| 查看次数: |
2541 次 |
| 最近记录: |