微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐