zoukankan      html  css  js  c++  java
  • 执行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


  • 相关阅读:
    twisted 初体验
    移动互联网实战--wifi定位和架构
    SpringCloud之Eureka集群
    com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
    SpringCloud服务注册与服务发现之Eureka
    SpringCloud简介
    Java实时监控类库Metrics
    InfluxDB Java入门
    InfluxDB配置文件详解
    InfluxDB概念和基本操作
  • 原文地址:https://www.cnblogs.com/smartsmile/p/6234026.html
Copyright © 2011-2022 走看看