开发者

Filtering SqlServer Command Timeout Exception for ExecReader

开发者 https://www.devze.com 2023-01-16 16:30 出处:网络
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.

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 ?

0

精彩评论

暂无评论...
验证码 换一张
取 消