0
可能重複:
How to catch SQLServer timeout exceptionsSqlCommand.CommandTimeout達到
我有以下代碼:
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["MainDll"].ToString()))
{
connection.Open();
using (SqlCommand command = new SqlCommand(sql.ToString(), connection))
{
command.CommandType = CommandType.Text;
command.CommandTimeout = 300;
returnCode = (string)command.ExecuteScalar();
//Dispose();
}
}
我怎麼知道什麼時候達到超時?我想抓住它,並在超時後用SQL做一些事情。
它應該在達到命令超時時發生錯誤。 – Brian 2012-07-30 18:36:04
新的SqlConnection(ConfigurationManager.ConnectionStrings [ 「MAINDLL」]。的ToString())) 大概應該是 新的SqlConnection(ConfigurationManager.ConnectionStrings [ 「MAINDLL」]。的ConnectionString) – Mithrandir 2012-07-30 18:39:33
@Raphael,這似乎是一個很好的鏈接和我會用這個 – cdub 2012-07-30 18:46:23