我想在select查询中指定自己的超时执行。
e.g.; select timeout(5) * from tableName (time exceeded, because records will not arrive before 50 seconds)
or
e.g.;
set timeout(5)
select * from tableName (time exceeded, because records will not arrive before 50 seconds)
答案 0 :(得分:0)
可以在代码中
using (SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnStringName"].ToString()))
using (SqlCommand mySqlCommand = new SqlCommand())
{
try
{
conn.Open();
mySqlCommand.Connection = conn;
mySqlCommand.CommandType = CommandType.StoredProcedure;
mySqlCommand.CommandText = "getCities";
mySqlCommand.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["ConnectionTimeout"].ToString());
mySqlCommand.Parameters.Add("@param", SqlDbType.VarChar).Value = param;
da.SelectCommand = mySqlCommand;
da.Fill(ds, "cities");
}
catch (Exception ex)
{
}
} // end using
------------你可以试试
OPENQUERY(Transact-SQL)
http://technet.microsoft.com/en-us/library/ms188427.aspx
检查一下:
连接OPENDATASOURCE
http://technet.microsoft.com/en-us/library/ms179856.aspx
连接超时DBPROP_INIT_TIMEOUT连接尝试失败后的超时值。