本文介绍了如何延长SQL连接超时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的按钮单击事件中,我调用一个SQL存储过程,在该过程完成后调用函数RefreshList();但是该过程有时需要50秒才能完成.如果过程未在30秒内完成,则光标变为箭头,然后调用函数RefreshList();但函数RefreshList()不起作用,因为过程尚未在数据库中完成.所以认为默认超时是30秒,是否有办法延长它?

代码:

尝试
{

SqlConnection conn =新SqlConnection(@数据源= R \ SQLEXPRESS;初始目录=梭哈;集成安全性= True");
SqlCommand cmd =新SqlCommand("ExecuteProcedure13",conn);
cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.Add("@ Paramater1",textBlock1.Text);

if(conn.State.Equals(ConnectionState .Closed))
{
Cursor = Cursors.AppStarting;
conn.Open();
cmd.ExecuteNonQuery();
}

///当执行完成或经过30秒后,会发生以下情况:

conn.Close();
Cursor = Cursors.Arrow;
RefreshList();

}
捕获(异常err)
{
MessageBox.Show(err.Message); //没有显示错误消息,则表示30秒过去了,执行没有返回.
}

In my button click event I call a SQL stored procedure, after the procedure is completed is call a function RefreshList(); But that procedure sometimes takes 50 seconds to complete. If the procedure has not finished in 30 seconds the Cursor becomes Arrow and then calls the function RefreshList(); but the function RefreshList() does not work because procedure is not finished yet in database. So think that the default timeout is 30 seconds, is there a way to extend it?

code:

try
{

SqlConnection conn = new SqlConnection(@"Data Source=R\SQLEXPRESS;Initial Catalog=Stud;Integrated Security=True");
SqlCommand cmd = new SqlCommand("ExecuteProcedure13", conn);
cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.Add("@Paramater1", textBlock1.Text);

if (conn.State.Equals(ConnectionState.Closed))
{
Cursor = Cursors.AppStarting;
conn.Open();
cmd.ExecuteNonQuery();
}

//the following happens when execution is complete or 30 seconds has passed:

conn.Close();
Cursor=Cursors.Arrow;
RefreshList();

}
catch(Exception err)
{
MessageBox.Show(err.Message); //no error message is displayed then 30 seconds has passed and execution has not returned
}

推荐答案


这篇关于如何延长SQL连接超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 20:14