作者:额 | 来源:互联网 | 2023-10-11 11:37
IneedtospecificallycatchSQLservertimeoutexceptionssothattheycanbehandleddifferently.
I need to specifically catch SQL server timeout exceptions so that they can be handled differently. I know I could catch the SqlException and then check if the message string Contains "Timeout" but was wondering if there is a better way to do it?
我需要特别捕获SQL server超时异常,以便能够以不同的方式处理它们。我知道我可以捕获SqlException,然后检查消息字符串是否包含“Timeout”,但我想知道是否有更好的方法来执行它?
try
{
//some code
}
catch (SqlException ex)
{
if (ex.Message.Contains("Timeout"))
{
//handle timeout
}
else
{
throw;
}
}
3 个解决方案