Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# aspx页面中出现超时过期错误_C#_Asp.net_Sql Server - Fatal编程技术网

C# aspx页面中出现超时过期错误

C# aspx页面中出现超时过期错误,c#,asp.net,sql-server,C#,Asp.net,Sql Server,我在aspx中有一个页面,后面有.aspx.vb格式的代码。此代码使用SQL编写的存储过程。此代码在测试服务器中运行时没有任何问题,但在生产服务器中出现超时错误: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. Description: An unhandled exception occurred during

我在aspx中有一个页面,后面有.aspx.vb格式的代码。此代码使用SQL编写的存储过程。此代码在测试服务器中运行时没有任何问题,但在生产服务器中出现超时错误:

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.

[SqlException (0x80131904): Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.]
   System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +212
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +245
   System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1099
   System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +58
   System.Data.SqlClient.SqlDataReader.get_MetaData() +112
   System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +6319508
   System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +6320577
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +424
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +28
   System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +211
   System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +19
   System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) +19
   System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +221
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +573
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +161
   System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +2805078
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +27
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +261
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
   System.Web.UI.WebControls.GridView.OnPreRender(EventArgs e) +46
   System.Web.UI.Control.PreRenderRecursiveInternal() +108
   System.Web.UI.Control.PreRenderRecursiveInternal() +224
   System.Web.UI.Control.PreRenderRecursiveInternal() +224
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3394
我尝试在连接字符串中添加连接超时,如:

    <add name="ConnectionString1" connectionString="Data Source=ExampleServer;Initial Catalog=Exampledb;Persist Security Info=True; Connect Timeout = 300; User ID=test;Password=test" 
providerName="System.Data.SqlClient" />

在querystring中添加连接超时无效。奇怪的是,它在测试环境中没有给出错误,但在生产环境中却给出了这个错误。我尝试在MicrosoftSQLSManagementStudio中运行存储过程,查询运行时间为2-3秒,并在不花费长时间的情况下快速输出。我比较了测试环境和生产环境的aspx代码、代码隐藏和存储过程,没有区别

有什么建议或想法可能导致这种情况吗

正在执行存储过程:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>" SelectCommand="EXEC   [dbo].[Example_StoredProcedure]
        @year1 = @year1,
        @term1Term = @term1,
        @year2 = @year2,
        @term2 = @term2,
        @year3 = @year3,
        @term3 = @term3,
        @year4 = @year4,
         @term4 = @term4
        ">

此SqlDataSource1正在用作:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False " 
                DataSourceID="SqlDataSource1" EnableModelValidation="True" AllowSorting="True"
               >

这与连接超时无关,而是与连接超时有关。 多次调用同一请求会导致SQL Server从缓存中加载该请求-这可能是导致2-3秒的快速结果的原因

string expr = "sp_YourProcedure";
DataSet ds = new DataSet();
using (SqlConnection Conn = new SqlConnection(YourConnString))
{
    using (SqlCommand sCommand = new SqlCommand(expr, Conn))
    {
        sCommand.CommandType = CommandType.StoredProcedure;
        sCommand.CommandTimeout = 600; // set CommandTimeout here
        SqlDataAdapter sdAdapter = new SqlDataAdapter(sCommand);
        sdAdapter.Fill(ds);
    }
}

您确定生产服务器没有网络问题(防火墙配置)可能会阻止它与数据库通信吗?您好,Mason,对于同一服务器中的其他代码和查询,我们没有遇到任何问题。就这一个我们遇到了问题。嗨,我们正在使用SqlDatasource执行存储过程。我已经编辑了代码,如上面所列:“执行存储过程”。在这种情况下,我怎么能使用CommandTimeout呢?你必须进入SqlDataSource选择事件:
protectedvoidSqlDataSource1\u选择(objectsender,SqlDataSourceSelectingEventArgs e){e.Command.CommandTimeout=30;}
这里解释得很好:如果你要使用mySQL,您可以在ConnectionString中设置CommandTimeout:-)你好,fubo,我在我的代码隐藏中添加了代码。我的代码是.aspx.vb格式的。我添加了:protected void SqlDataSource1_Selecting(对象发送方,SqlDataSourceSelectingEventArgs e){e.Command.CommandTimeout=300;},但我得到了以下错误:BC30205:预期语句结束。知道我需要在.vb端做什么吗。这是旧代码,他们正在使用:Protected Sub…End Sub。我也试过了,但没有成功。有没有关于如何关闭此空白的建议?我在.aspx.vb中的代码隐藏中添加了这样的内容:受保护的子SqlDataSource1_Selecting(ByVal sender作为对象,ByVal e作为SqlDataSourceSelectingEventArgs)e.Command.CommandTimeout=300 End sub这并没有给我语法错误或任何东西。但仍然得到相同的超时错误。