我正在使用WebApi和AngularJS开发应用程序.我花了一些时间申请后得到这个例外.我在这个应用程序中使用EntityFramework.
“超时已到期.在从池中获取连接之前已经过了超时时间.这可能是因为所有池连接都在使用中并且达到了最大池大小.”
堆栈跟踪
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,DbConnectionOptions userOptions) at System.Data.sqlClient.sqlConnection.TryOpen(TaskCompletionSource`1 retry) at System.Data.sqlClient.sqlConnection.Open() at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition,DbConnection storeConnectionToOpen,DbConnection originalConnection,String exceptionCode,String attemptedOperation,Boolean& closeStoreConnectionOnFailure)
解决方法
关闭数据库连接(这非常重要).
sqlConnection myConnection = new sqlConnection(ConnectionString); try { conn.Open(); someCall (myConnection); } finally { myConnection.Close(); }
要么
using (sqlConnection myConnection = new sqlConnection(ConnectionString)) { myConnection.Open(); someCall(myConnection); }
检查连接到数据库的用户数以及查询的超时时间.如果您有很长时间执行查询,请检查.
也许,重复的问题:
How can I solve a connection pool problem between ASP.NET and SQL Server?