通过配置更改默认的 SqlCommand CommandTimeout 而不是重新编译?

发布于 2024-07-24 22:07:57 字数 2521 浏览 4 评论 0原文

我支持 ASP.Net 3.5 Web 应用程序,用户在尝试运行报告时在 30 秒后遇到超时错误。 环顾网络,似乎很容易更改代码中的超时,不幸的是我无法访问代码并重新编译。 是否有办法为 Web 应用程序、工作进程、IIS 或整个机器配置默认值?

这是直到 System.Data 中的堆栈跟踪,以防万一我错过了其他一些问题:

[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) +1948826
  System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4844747
  System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194
  System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2392
  System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +33
  System.Data.SqlClient.SqlDataReader.get_MetaData() +83
  System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +297
  System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +954
  System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +162
  System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32
  System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +141
  System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +12
  System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) +10
  System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +130
  System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior) +162
  System.Data.Common.DbDataAdapter.Fill(DataTable dataTable) +115

--Edit

There must be Something Outside the code本身 - 我已经下载了数据库并在同一个网络上运行它安装在测试服务器上的站点,运行时间超过 30 秒并返回报告。 我比较了实时和测试中 .Net 目录中的 machine.config 和 web.config 文件,它们看起来是相同的,比较了两个 IIS 设置,还查看了 SQL Server 配置,唯一的区别是实时服务器集群在 64 位 W2K3 上,而测试服务器集群在 32 位上。

I am supporting an ASP.Net 3.5 web application and users are experiencing a timeout error after 30 seconds when trying to run a report. Looking around the web it seems it's easy enough to change the timeout in the code, unfortunately I'm not able to access the code and recompile. Is there anyway to configure the default for either the web app, the worker process, IIS or the whole machine?

Here is the stack trace up to the point where it's in System.Data in case I'm missing some other problem:

[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) +1948826
  System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4844747
  System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194
  System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2392
  System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +33
  System.Data.SqlClient.SqlDataReader.get_MetaData() +83
  System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +297
  System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +954
  System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +162
  System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32
  System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +141
  System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +12
  System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) +10
  System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +130
  System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior) +162
  System.Data.Common.DbDataAdapter.Fill(DataTable dataTable) +115

--Edit

There must be something outside the code itself - I've downloaded the database and run it against the same web site installed on a test server and it runs for longer than 30 seconds and returns the report. I've compared the machine.config and web.config files from the .Net directory on the live and test and they seem the same, compared the two IIS setups, also looked at the SQL Server configuration and the only difference is that the live server is clustered on 64bit W2K3 while the test server is on 32bit.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

§普罗旺斯的薰衣草 2024-07-31 22:07:57

不幸的是,我过去读过的有关此内容的所有内容都说不,无法通过配置进行控制。 这真是太糟糕了。

Unfortunately, everything I've read about this in the past says no, can't be controlled via configuration. Which is a bummer.

壹場煙雨 2024-07-31 22:07:57

抱歉,您无法通过连接字符串或某些外部设置来设置命令超时。

有时,驱动程序会将连接字符串中的“超时”参数解释为连接超时和命令超时周期,但这在技术上是一个“错误”。 一定要喜欢这些标准。

You cannot set the command timeout from the connection string or some external setting, sorry.

Sometimes a driver will interpret the 'timeout' parameter in the connection string as both Connect Timeout and Command Timeout period, but that is technically a "bug". Gotta love the standards.

善良天后 2024-07-31 22:07:57

据我所知,您可以在连接字符串中设置连接超时,该连接字符串控制 ADO 在尝试连接到 SQL Server 时等待的时间,并且不会影响命令超时。

我个人认为应该有办法改变这个设置。 假设其中的程序集不是强命名的,您最好的选择可能是对代码进行逆向工程,修改源代码并使用新名称重新部署程序集。

The best I know of is you can set a Connection Timeout in the connection string which controls how long ADO will wait while trying to connect to SQL Server and doesn't impact the Command Timeout.

Personally I think there should be a way to change this setting. Assuming the assembly this is in is not strong named your best bet might be to reverse engineer the code modify the source and redeploy the assembly with the new name.

凉世弥音 2024-07-31 22:07:57

不过自己动手也不太难吧? 只需在 AppSettings 下创建自定义 SqlCommandTimeout 设置即可。 如果您已经使用某种 SqlCommandFactory 来创建 SqlCommand 或拥有某种 SqlCommand 基类,那么您可以轻松进行更改。 如果没有,那么您可能不太关心您的代码,无论如何都不想将其放入配置文件中。

问候,
詹姆士

It's not too hard to roll your own though? Just create a custom SqlCommandTimeout setting under AppSettings. If you are already using some sort of SqlCommandFactory to create your SqlCommand or have some sort of SqlCommand base class then you can easily make the change. If not then you probably don't care enough about your code to want to put this in a configuration file anyway.

Regards,
James

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文