我的一个Sql语句在查询分析器中执行的时间是3分钟,但是在程序就打开却出现错误:Server Error in '/' Application.
--------------------------------------------------------------------------------Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.Source Error: 部分程序如下: Dim ConnStr As String
        ConnStr = System.Configuration.ConfigurationSettings.AppSettings("kingseer_dbConnectionString").ToString
        Dim MyConnection As SqlClient.SqlConnection
        MyConnection = New SqlClient.SqlConnection(ConnStr)
        MyConnection.Open()
string sql="select * from table"
Dim dsdataSet As New DataSet1()        Dim daOrders As New Data.SqlClient.SqlDataAdapter(sql, MyConnection)
        daOrders.Fill(dsdataSet, "t_biao_cnskb")        '使用“报表引擎”对象模型将填充的数据集,传递给报表
        oRpt.SetDataSource(dsdataSet)
        CrystalReportViewer1.ReportSource = oRpt请回答,谢谢! 

解决方案 »

  1.   

    SqlCommand.CommandTimeout 属性设长一点,比如5分钟
      

  2.   

    不过,还是首先应该优化你的sql啊
      

  3.   

    SqlCommand.CommandTimeout 可以设置timeout属性
      

  4.   

    查询分析器中执行的时间是3分钟,太长了:
    如果你的数据太大,可以用分页,每次返回一部分数据;
    尽量不要用 select *,用什么字段写什么字段;
    如果非要一次返回,设下 SqlCommand.CommandTimeout 
      

  5.   

    谢谢各位,不过我用的不是SqlCommand,而是SqlDataAdapter,我看他没有CommandTimeout 属性啊。Dim daOrders As New Data.SqlClient.SqlDataAdapter(sql, MyConnection) 
    daOrders.Fill(dsdataSet, "t_biao_cnskb") 
      

  6.   

    SqlConnection有ConnectionTimeout属性,用这个。
      

  7.   

    具体怎么写呢?我是新手。谢谢
      Dim ConnStr As String
            ConnStr = System.Configuration.ConfigurationSettings.AppSettings("kingseer_dbConnectionString").ToString
            Dim MyConnection As SqlClient.SqlConnection        MyConnection = New SqlClient.SqlConnection(ConnStr)        MyConnection.Open()
            MyConnection.ConnectionTimeout = 500这么写不对。
      

  8.   

     比如:
    /// <summary>
    /// 执行查询语句,返回DataSet
    /// </summary>
    /// <param name = "SQLString">查询语句</param>
    /// <returns>DataSet</returns>
    public static DataSet Query(string SQLString)
    {
    using (SqlConnection connection = new SqlConnection(connectionString))
    {
    DataSet ds = new DataSet();
    try
    {
    connection.Open();
    //SQLString = ClearSQLString(SQLString);
    SqlDataAdapter command = new SqlDataAdapter(SQLString,connection);
    command.SelectCommand.CommandTimeout = 300;//300s
    command.Fill(ds,"ds");
    }
    catch(System.Data.SqlClient.SqlException ex)
    {
    //Utility.Logs.WriteLogFile(ex,SQLString);
    throw new Exception(ex.Message);
    }
    finally
    {
    connection.Close();
    connection.Dispose();
    }
    return ds;
    }
    }