C#.net中的超时异常

4
 public DataTable GetDailycardReport(DailyReportPL dailyreportpl)
    {
        DataTable dtGetDailycardReport = new DataTable();
        try
        {
            SqlParameter[] arParams = new SqlParameter[2];

            arParams[0] = new SqlParameter("@farmername", typeof(string));
            arParams[0].Value = dailyreportpl.farmername;

            arParams[1] = new SqlParameter("@batchno", typeof(int));
            arParams[1].Value = dailyreportpl.batchno;

            dtGetDailycardReport.Load(SqlHelper.ExecuteReader(connection.ConnectionString, CommandType.StoredProcedure, "k_DailyCardreport", arParams));
        }
        catch (Exception ex)
        {

            //DBExceptionPublisher exc = new DBExceptionPublisher();
            //exc.Publish(ex);
        }
        finally
        {

        }
        return dtGetDailycardReport;

    }

异常::

"Timeout expired.  The timeout period elapsed prior to completion of 
    the operation or  the   server is not responding."

当我向存储过程传递参数时,它会抛出异常并显示如上所述的消息。如何在webconfig文件中将命令超时时间增加到200。我在谷歌上搜索了,但没有得到最优结果。

2个回答

8

您也可以在命令对象上设置它

   cmd.CommandTimeout = 60;

请在秒中指定您的时间。


1
“或者服务器没有响应”在技术上可能是一个“连接超时”问题。 - Erik Philips
2
@BobbyDigital 技术上讲,“操作完成前超时时间已过”可能是“CommandTimeout”问题。 - Erik Philips

6

这可以在连接字符串中设置,如下所示,其中设置为200秒。

"数据源=(local);初始化目录=AdventureWorks;综合安全性=SSPI;连接超时=200"

来源


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接