我收到此错误,导致我的应用程序停止工作。 Timeout expired.
在从池中获取连接之前已过超时期限。
这可能是因为所有池连接都在使用中并且已达到最大池大小。
但是我还没有达到我的最大连接池。我有 RDS,在我的监控页面中,我发现发生此错误时连接数为 33,默认情况下我的最大连接数为 100。
所以,我想知道这可能是由于我的连接泄漏所致。
这是我用来连接数据库的 DBLayer
类。
public static DataTable GetDataTable(SqlCommand command, IsolationLevel isolationLevel = IsolationLevel.ReadUncommitted)
{
using (new LoggingStopwatch("Executing SQL " + command.CommandText, command.Parameters))
{
using (var connection = new SqlConnection(connectionString))
using (var dataAdapter = new SqlDataAdapter(command))
{
command.Connection = connection;
command.CommandTimeout = ShopexConfiguration.SqlTimeout;
connection.Open();
var transaction = connection.BeginTransaction(isolationLevel);
command.Transaction = transaction;
try
{
var result = new DataTable();
dataAdapter.Fill(result);
transaction.Commit();
return result;
}
catch
{
try
{
transaction.Rollback();
}
catch (Exception)
{
//
// This catch block will handle any errors that may have occurred
// on the server that would cause the rollback to fail, such as
// a closed connection.
}
throw;
}
}
}
}
我只是想知道,这会导致连接泄漏吗?
我看过这个博客:
需要任何帮助吗?
最佳答案
您确定您的查询没有达到执行超时吗? SqlConnection.ConnectionTimeout有默认值 15 秒
您的 connectionString 格式中是否也有一些连接超时值:"...;Connection Timeout=10..."
关于c# - 连接泄漏可能会导致超时过期。从池中获取连接之前超时时间已过?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39991658/