加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – SQL Timeout过期2秒查询

发布时间:2020-12-16 04:05:48 所属栏目:asp.Net 来源:网络整理
导读:问题是我有一个存储过程在Sql Server Management Server中以2秒的时间一致地运行,但是当从代码调用相同的存储过程时它会超时. 当它从SSMS正确运行时,它应该返回大约30行. 我尝试了几种不同的方法从代码调用过程,但每次都有相同的结果.这刚刚开始发生,昨天它
问题是我有一个存储过程在Sql Server Management Server中以2秒的时间一致地运行,但是当从代码调用相同的存储过程时它会超时.

当它从SSMS正确运行时,它应该返回大约30行.

我尝试了几种不同的方法从代码调用过程,但每次都有相同的结果.这刚刚开始发生,昨天它工作正常.

为我们调用该过程的首选方法是使用Linq2Sql,它给出以下错误消息:

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:

Line 16:         public IMultipleResults GetTournamentRatingNonComplaintData([global::System.Data.Linq.Mapping.ParameterAttribute(DbType = "DateTime")] System.Nullable<System.DateTime> startdate,[global::System.Data.Linq.Mapping.ParameterAttribute(DbType = "DateTime")] System.Nullable<System.DateTime> enddate,[global::System.Data.Linq.Mapping.ParameterAttribute(DbType = "Int")] System.Nullable<int> officialSportID,[global::System.Data.Linq.Mapping.ParameterAttribute(DbType = "Char(1)")] System.Nullable<char> gender,[global::System.Data.Linq.Mapping.ParameterAttribute(DbType = "Int")] System.Nullable<int> level)
Line 17:         {
Line 18:             IExecuteResult result = this.ExecuteMethodCall(this,((MethodInfo)(MethodInfo.GetCurrentMethod())),startdate,enddate,officialSportID,gender,level);
Line 19:             return ((IMultipleResults)(result.ReturnValue));
Line 20:         }

有谁知道在SSMS中运行它和通过代码之间的区别是什么?如何解决此问题可以做些什么?

解决方法

您在SQL Management Studio中的连接可能与您在.NET中使用的连接字符串的配置不同.

例如,请参阅SQL Management Studio工具/选项/查询执行/ SQL Server / Advanced中默认设置的选项.

我怀疑这两种环境之间的某些设置不同会导致您的问题.要进行调试,您应该尝试将SQL Server Management Studio配置为在运行SP之前使用与.NET连接字符串相同的配置.

或者,将SET语句添加到.NET查询中以配置您在Management Studio中配置的所有选项.

找到不同的设置并不总是很容易 – 根据我的经验,一个常见的原因是不同的ANSI设置.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读