【问题标题】:Asp.net web form "The wait operation timed out"Asp.net web 表单“等待操作超时”
【发布时间】:2017-07-06 17:45:26
【问题描述】:

我构建了一个 Web 表单,用于从报告服务器检索数据。我无权在该服务器中查询的表上创建索引,并且查询在文本查找中非常非常慢。我已经尝试优化查询中的内容,但它会很慢。所以我需要找到一种方法来避免网页本身超时。我已经查看了几个类似的问题,我设置了一个疯狂的高连接超时,但我仍然在按钮单击时获得等待操作超时。超时发生在 30 秒后,即使我设置了如此高的连接超时。我不知道它是否是网络配置,但我没有使用我的网络配置中定义的连接字符串,只是代码隐藏中的这个。查询不会在 SSMS 中超时,仅在从网络表单访问数据时(从技术上讲,它在连接字符串中使用我的登录凭据,因此没有任何权限问题,其他部分运行良好)。还有什么我需要增加页面超时的地方吗?

连接字符串(un/pw x'ed out for privacy):

server=lxxxxxx.resources.xxx; Initial Catalog=pxxxxxxxx;User ID=mfeXXXXX;Password=XXXXXX;Trusted_Connection=False; Connection Timeout=10000"

查询超时,如果有帮助的话:

 protected void btnSearchFeedback_Click(object sender, EventArgs e)
    {
        con.Open();
        SqlDataAdapter sdaFeedBack = new SqlDataAdapter("SELECT CTIR.portion_ID, IB.Item_ID as [Item ID], CTIR.Item_DBkey as [Item DB Key], CTIR.Feedback as [Feedback], CTA.date as [Date],CTA.Candidate_ID as [Candidate ID] FROM Canxxxxxxx CTIR WITH (NOLOCK) left join Ixxxxx IB WITH (NOLOCK) ON CTIR.xxxxx = IB.xxxxx left join Cxxxxxx CTA WITH (NOLOCK) ON CTxxxxxx = CTxxxxxxx where (ctir.portion_id in (" + portionIDTextBox.Text + ") ) AND (len(CTIR.Feedback) > 0) and CTA.Date  > '2015-02-01 00:00:00.000' order by [Date]", con);
        DataSet dtFeedBack = new DataSet();
        sdaFeedBack.Fill(dtFeedBack);
        ViewState["dtFeedback"] = dtFeedBack;
        rptFeedBack.DataSource = dtFeedBack;
        rptFeedBack.DataBind();
        con.Close();
    }

再次,为了安全起见,删除了表名。所以我想看看是否有另一个位置我需要将连接超时设置为更高的数字以避免“'/'应用程序中的服务器错误。等待操作超时”,或者这是需要处理的事情在服务器端?

这是确切的错误:

“/”应用程序中的服务器错误。

等待操作超时 说明:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

异常详细信息:System.ComponentModel.Win32Exception:等待操作超时

堆栈跟踪: [Win32Exception (0x80004005): 等待操作超时]

[SqlException (0x80131904): 超时。在操作完成之前超时时间已过或服务器没有响应。] System.Data.SqlClient.SqlConnection.OnError(SqlException异常,布尔breakConnection,Action1 wrapCloseInAction) +2434922 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction)+5736592 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj,布尔调用者HasConnectionLock,布尔异步关闭)+285 System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +3731 System.Data.SqlClient.SqlDataReader.TrySetMetaData(_SqlMetaDataSet metaData, Boolean moreInfo) +198 System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +2852 System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() +58 System.Data.SqlClient.SqlDataReader.get_MetaData() +89 System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds,RunBehavior runBehavior,字符串 resetOptionsString)+379 System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,Boolean async,Int32 超时,Task& 任务,Boolean asyncWrite,SqlDataReader ds,Boolean describeParameterEncryptionRequest)+2026 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,String 方法,TaskCompletionSource`1 完成,Int32 超时,Task& 任务,Boolean asyncWrite)+375 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String 方法) +53 System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior 行为,字符串方法)+240 System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior 行为)+41 System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior 行为)+12 System.Data.Common.DbDataAdapter.FillInternal(DataSet 数据集,DataTable[] 数据表,Int32 startRecord,Int32 maxRecords,String srcTable,IDbCommand 命令,CommandBehavior 行为)+139 System.Data.Common.DbDataAdapter.Fill(DataSet dataSet,Int32 startRecord,Int32 maxRecords,String srcTable,IDbCommand 命令,CommandBehavior 行为)+136 System.Data.Common.DbDataAdapter.Fill(DataSet 数据集) +88 C:\Users\mfelchlin\Documents\Visual Studio 2015\WebSites\devFormsSite\FeedBackForm.aspx.cs:27 中的 FeedBackForm.btnSearchFeedback_Click(Object sender, EventArgs e) System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9696694 System.Web.UI.WebControls.Button.RaisePostBackEvent(字符串事件参数)+204 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(字符串 eventArgument)+12 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +15 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1639

【问题讨论】:

  • 我很难相信 X'ing 你的表名会增加安全性。您是表名敏感数据吗?无论如何,我发现您更有可能需要提高查询性能而不是增加超时时间。此外,您没有正确处理您的 IDisposable 对象。而且由于您没有使用参数化查询,因此您的代码容易受到 SQL 注入攻击。此外,连接超时与命令超时不同。你得到的确切错误是什么?
  • 这样做不会改变或降低某人能够理解问题的可能性,所以如果它让我更舒服,我真的不明白为什么会出现问题。
  • 我只是好奇你为什么要这么做。似乎是在浪费时间和“安全剧院”。你是对的,这不是问题。
  • 此查询在 SSMS 中执行需要多长时间?

标签: c# asp.net tsql connection-timeout


【解决方案1】:
sdaFeedBack.SelectCommand.CommandTimeout=120; //or some other number of seconds.

设置连接超时决定了等待连接打开的时间,而不是命令执行的时间。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-02
    • 1970-01-01
    • 2017-01-03
    • 1970-01-01
    • 1970-01-01
    • 2022-08-23
    • 1970-01-01
    相关资源
    最近更新 更多