2017-11-15 26 views
0

System.Data;タイムアウトが切れました。プールから接続を取得する前にタイムアウト期間が経過しています。これは、プールされたすべての接続が使用中で、プールの最大サイズに達したために発生した可能性があります。 このエラーは、私がサービスタイムアウトがタイムアウトしました。エラー

を実行する場合にのみ、私はいつかそれがデフォルトの接続時間以上かかるので、あなたのコマンドにタイムアウトを設定しようとするあなたのしようとしてテイクDBのバックアップとしてコード

try 
{ 
    LogGenerator.WriteErrorLog("Conn opened before"); 
    if (con.State == System.Data.ConnectionState.Closed) 
    con.Open(); 
    LogGenerator.WriteErrorLog("Conn opened"); 
    // Set up a command with the given query and associate 
    // this with the current connection. 
    SqlCommand cmd = new SqlCommand("Backup database " + DBName + " to disk='" + filePathExist + "'", con); 
    cmd.ExecuteNonQuery(); 
    LogGenerator.WriteErrorLog("query executed"); 
} 
catch(Exception ex) 
{ 
    LogGenerator.WriteErrorLog("Error in Conn"); 
    LogGenerator.WriteErrorLog(ex); 
} 
finally 
{ 
    con.Close(); 
    con.Dispose(); 
    SqlConnection.ClearPool(con); 
} 
+0

CommandTimeoutのための30秒を持っています。バックアップが長く実行されると、タイムアウトエラーが発生します。ですから、私はcmd.ExecuteNonQuery()の前にCommandTimeoutを増やすべきだと思います。 –

答えて

0

の下に使用しています来ます。

try 
{  
    if (con.State == System.Data.ConnectionState.Closed) 
     con.Open();  
// Set up a command with the given query and associate 
// this with the current connection. 
    SqlCommand cmd = new SqlCommand("Backup database " + DBName + " to disk='" + 
    filePathExist + "'", con); 
    cmd.CommandTimeout = 60; 
    cmd.ExecuteNonQuery();  
}  
catch(Exception ex) 
{ 
    //handle exception here 
} 
finally 
{ 
    con.Close(); 
    con.Dispose(); 
    SqlConnection.ClearPool(con); 
} 

タイムアウトの詳細については、こちらを参照してください。デフォルトのcmdで https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.commandtimeout(v=vs.110).aspx

https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/configure-the-remote-login-timeout-server-configuration-option

関連する問題