private static string connectionString = RBAC.Dal.DataRootBase.ConnectionString;
private SqlConnection mConnection = new SqlConnection(connectionString);

#region
/// <summary>
/// 当点击执行查询时发生(异步操作) 
/// 执行数据库waitfor delay延时存储过程
/// 或者waitfor time定时存储过程
/// </summary>
private void Button_DoSearch_Click(object sender, EventArgs e)
{
	SqlCommand command = new SqlCommand("pro_StoreDelay", mConnection);
	command.CommandType = CommandType.StoredProcedure;
	mConnection.Open();
	AsyncCallback callBack = new AsyncCallback(HandleCallback);//注册回调方法
	//开始执行异步查询,将Command作为参数传递到回调函数以便执行End操作
	command.BeginExecuteReader(callBack, command); //异步查询 回调
	//command.BeginExecuteNonQuery(null, command); //直接执行 无回调
}
#endregion

#region
/// <summary>
/// 异步查询的回调方法
/// </summary>
/// <param name="MyResult">异步操作状态</param>
private void HandleCallback(IAsyncResult MyResult)
{
	try
	{
		//SqlCommand command = (SqlCommand)MyResult.AsyncState;
		//SqlDataReader reader = command.EndExecuteReader(MyResult);
		//DataTable dataTable = new DataTable();
		//dataTable.Load(reader);
		//reader.Dispose();
		//command.Dispose();
	}
	catch (Exception ex)
	{
	}
	finally
	{
		if (mConnection != null)
		{
			mConnection.Close();  //回调后关闭连接
		}
	}
}
#endregion

执行Sqlserver中waitfor delay延时操作或waitfor time定时操作

相关文章:

  • 2021-10-03
  • 2022-12-23
  • 2021-07-25
  • 2021-09-18
  • 2021-08-17
  • 2021-11-10
  • 2021-10-23
猜你喜欢
  • 2021-10-31
  • 2021-12-16
  • 2022-03-11
  • 2021-11-07
  • 2022-12-23
  • 2022-12-23
  • 2021-05-21
相关资源
相似解决方案