今天系統突然遇到SQL執行TIMEOUT的問題,
程式如何CATCH這個問題,很簡單,運用"SQLException"就可以了,語法如下:
程式如何CATCH這個問題,很簡單,運用"SQLException"就可以了,語法如下:
try
{
command.Connection.Open();
command.ExecuteNonQuery();
}
catch (SqlException ex)
{
for (int i = 0; i < ex.Errors.Count; i++)
{
errorMessages.Append("Index #" + i + "\n" +
"Message: " + ex.Errors[i].Message + "\n" +
"Error Number: " + ex.Errors[i].Number + "\n" +
"LineNumber: " + ex.Errors[i].LineNumber + "\n" +
"Source: " + ex.Errors[i].Source + "\n" +
"Procedure: " + ex.Errors[i].Procedure + "\n");
}
Console.WriteLine(errorMessages.ToString());
}
switch ( sqlException.Number )
{
case -2: // Client Timeout
case 701: // Out of Memory
case 1204: // Lock Issue
case 1205: // >>> Deadlock Victim
case 1222: // Lock Request Timeout
case 8645: // Timeout waiting for memory resource
case 8651: // Low memory condition
...
}
留言