C#中的连接超时

时间:2015-02-16 06:55:47

标签: c# sql-server-2008 connection timeout

我正在运行一个从数据库加载过多数据的应用程序,我没有任何错误的代码或任何东西,但每次加载太多数据时我都会遇到此异常

  

超时已过期。在完成之前经过了超时时间   操作或服务器没有响应。

     

警告:聚合或其他SET操作消除了空值。

以下是我在gridview中加载数据的代码

 private void toolStripCompute_Click(object sender, EventArgs e)
    {
        //LoadData();
        #region Threading Begin
        //this.dgvCommision.Enabled = false;
        oProgressBar.Visible = true;
        lblProgress.Visible = true;
        oProgressBar.Value = 0;
        BackgroundWorker worker = new BackgroundWorker();
        worker.DoWork += new DoWorkEventHandler(worker_DoWork);
        worker.RunWorkerCompleted +=
        new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
        worker.RunWorkerAsync();
        #endregion      

       // worker_DoWork();
        //ComputeCommission();
    }

这是来自worker.DoWork += new DoWorkEventHandler(worker_DoWork)

的worker_DoWork代码
 void worker_DoWork(object sender, DoWorkEventArgs e)
   {
       try
        {
            timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_elapsed);
            timer.Start();
            Invoke(new MyDelegate(ShowLabel), "Loading...");

            BACS.DateFrom = this.dtFrom.Value.ToShortDateString(); //this.dtFrom.Text;
            BACS.DateTo = this.dtTo.Value.ToShortDateString(); //this.dtTo.Text;
            BACS.BrokerAgent = BrokerXML;
            BACS.Payor = PayorXML;
            DS = BACS.GET_SP_BACS_ComputeCommission();
            ReadData(DS, this.dgvCommision);
            CheckGrid();
            Thread.Sleep(1);
            timer.Stop();
        }
       catch
       { }
    }

这就是我从DS = BACS.GET_SP_BACS_ComputeCommission();加载我的sp命令的方法GET_SP_BACS_ComputeCommission是这个

public DataSet GET_SP_BACS_ComputeCommission()
    {
        SqlParameter[] sqlParam = new SqlParameter[4];
        sqlParam[0] = new SqlParameter("@DATEFROM", DateFrom);
        sqlParam[1] = new SqlParameter("@DATETO", DateTo);
        sqlParam[2] = new SqlParameter("@BROKERAGENT", BrokerAgent);
        sqlParam[3] = new SqlParameter("@PAYOR",Payor);

        DataSet ds = new DataSet();
        if (this.InitDataLayerObject() == true)
        {
            ds = this.ExecuteQuery("dbo.[SP_BACS_COMMISSION_COMPUTATION]", sqlParam);
        }
        return ds;
    }    

这有什么解决方案吗?我已尝试设置我的Connection Timeout=0我甚至将其更改为Connection Timeout=2500但仍然没有效果。

0 个答案:

没有答案