Filtering SqlServer Command Timeout Exception for ExecReader
How do get the specific exception that has caused a sql server command to happen using the SqlException object that I have caught. I want to know when a Command timeout has occured, i.e.
try
{
// database ExecReader call
}
catch (SqlException sqlEx)
{
// what can I test here to find if this is a command timeout exception
}
System.Data.SqlClient.SqlException: Timeout expired. The ti开发者_运维技巧meout period elapsed prior to completion of the operation or the server is not responding
Can I test sqlEx.Number or sqlEx.ErrorCode for the command timeout. Is there a list of codes (for sqlEx.Number) and there corresponding meanings, I have googled but can't seem to find one and do the codes change depending on the version of sql server that I am using?
Thanks for any help, Nick
Have you tried having a look here: How to catch SQLServer timeout exceptions ?
精彩评论