为了显示超时时间,&服务器无响应 [英] To shown time out expire & server not responding

查看:85
本文介绍了为了显示超时时间,&服务器无响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将大型批处理T-Sql(``某些列添加\某些数据类型'')执行到直接sql查询分析器并执行得很好.
但是当我通过编码运行此查询时,会出现错误消息msg.i.e.(``超时到期且服务器未响应'')

我该如何解决以上问题??
请帮助我任何指示....

I execute the large size of batch T-Sql(''Some column add\some data type'') to the direct sql Query analyzer & execute fine.
But when I run this query through coding, there is arise error msg.i.e.(''time out expire & server not responding'')

How will i solve above problem????
Please help me any instruction....

推荐答案

发生此错误是因为您的SQL命令执行时间超过30秒.我建议使用异步调用来执行此命令,因为它运行了那么长时间.此外,我建议将SQL代码放入存储过程中,以便可以对其进行编译和优化,这将减少其运行时间.但是,根本问题是通过C#运行命令超时.

解决方案是将SQLCommand对象的CommandTimeout值从30(秒)更改为所需的值,再加上一个缓冲区.代码如下所示:

This error is happening because your SQL command is taking longer than 30 seconds to execute. I would recommend using an asynchronous call to execute this command, since it is running that long. Further, I would recommend that the SQL code be put into a stored procedure so that it can be compiled and optimized, which will reduce how long it runs. However, the root issue is the command timeout when you run it via C#.

The solution is to change the SQLCommand objects CommandTimeout value from 30 (seconds) to whatever you need plus a buffer. Here is what the code would look like:

SqlCommand cmd = new SqlCommand("select * table1", connectionString);
cmd.CommandTimeout = 120;



这是一篇讨论您的错误并说明如何通过复制将其发生的文章:

^ ]

在那儿,作者将超时更改为十秒.您可以使用类似的代码,只将超时更改为不会像我上面那样出错的内容.



Here is an article that talks about your error and shows how it can happen by replicating it:

http://blogs.msdn.com/b/spike/archive/2008/07/31/timeout-expired-the-timeout-period-elapsed-prior-to-completion-of-the-operation-or-the-server-is-not-responding.aspx[^]

In there, the author changes the timeout to ten seconds. You can use similar code, only change the timeout to be something that won''t error like I did above.


这篇关于为了显示超时时间,&服务器无响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆