2016-10-12 9 views
3

このエラーが発生し、アプリケーションが動作を停止します。 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; 
      } 
     } 
    } 
} 

これは接続リークの原因になりますか?すべてのヘルプは高く評価され

https://blogs.msdn.microsoft.com/spike/2008/08/25/timeout-expired-the-timeout-period-elapsed-prior-to-obtaining-a-connection-from-the-pool/

私はこのブログを見たことがありますか?

+0

これは長引くかもしれませんが、サーバー*でユーザー1人あたりの開かれた接続数には制限がありますか? –

答えて

1

クエリが実行タイムアウトに達していないことを確認してください。 SqlConnection.ConnectionTimeoutはデフォルト値を持っている。また、あなたののConnectionString形式でいくつかの接続タイムアウト値を持っているん

15秒です:"....;接続タイムアウト= 10 ..."

+0

いいえ、時間外れではありません。以前はタイムアウトしましたが、私のアプリケーションは正常に動作していました。 elmahがエラーを記録できない場合でもこの例外が発生したとき、エラーの詳細を取得するために新しい遺物を使用する必要がありました。 – user123456

1

私はあなたを考えます以下のようなあなたのfinally声明の中で、あなたの接続を閉じる必要があります:あなたはあなたの電子を閉じずにcatchステートメントでトランザクションをrollbackingされているので

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. 
       } 
       finally { connection.Close(); } 
       throw; 
      } 
     } 
    } 
} 

は、多分それは、あなたの問題を解決あなたはSQL接続をオープンしようとしている前に、あなたはまた、条件の下に使用することができ、接続xisting:

if (connection.State == ConnectionState.Closed) { 
     // Open your connection here 
     connection.Open(); 
    } 
// Do your logic here 

することは、あなたを助け願っています。

ありがとうございます

+0

@ sunul Kamur URの答えをありがとう、私はそれをやっていると思っていた。しかし、私はtransaction.Rollebackは私のための接続を閉じる必要があります – user123456

+0

マークして、私のソリューションをupvoteしてくださいそれはあなたに役立つ場合は、感謝:) –

関連する問題