如何避免[System.Data.SqlClient.SqlException] = {“超时已过期. "} [英] how to avoid [System.Data.SqlClient.SqlException] = {"Timeout expired. "}

查看:103
本文介绍了如何避免[System.Data.SqlClient.SqlException] = {“超时已过期. "}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何避免[System.Data.SqlClient.SqlException] = {超时过期.在操作完成之前或服务器未经过的超时时间不是"}"
当我将要更新时,SQL查询更新联接查询的时间为每秒数据库中的1000条记录.将会显示此异常.
任何人都有关于此异常的想法

how to avoid [System.Data.SqlClient.SqlException] = {"Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not "}
when i will be update the SQL query update join query at time 1000 records in the database at every second. it will be shown this exception.
any one have idea about this exception
thanks in advance.

推荐答案

您可以更改
You can change SqlCommand.CommandTimeout[^] to are lager value then the default at 30 sec.


增加SQL连接超时的值& SQL命令

对于Web.Config中的连接,
Increase value for Timeout of your SQL Connection & SQL Command

For Connection in Web.Config,
<add key="ConnectionString" value="server=(local); uid=sa; password=sa; database=master;Connection Timeout=30" />


对于Command,


For Command,

public void CreateSqlCommand()
{
   SqlCommand cmd = new SqlCommand();
   cmd.CommandTimeout = 15;
   cmd.CommandType = CommandType.Text;
}


&也请看以下页面.
问题排查:超时已过期 [ DBA超时快速指南 [ ^ ]


& also take a look at the following page.
Troubleshooting: Timeout expired[^]

Free attachment
DBA’s Quick Guide to Timeouts[^]


增加命令超时将解决问题,但是您正在解决问题而不是原因

默认查询超时为30秒,因此假设您尚未更改此查询,则查询将花费30秒运行,然后报告超时.

您可以完全调整查询吗?

*查询中包括的所有表都正确索引了.表等上的聚集索引?
*您是否通过执行计划程序运行查询?有什么地方可以改进吗?
*仅需要更新的数据会被更新吗?

您绝对应该首先查看问题的根源,然后看看是否可以在此处进行改进.
Increasing the command timeout will solve the problem, but you are addressing the issue rather than the cause

Default query timeout is 30 seconds, so assuming you haven''t changed this your queries are taking 30 seconds to run and then reporting timeout.

Can you tune your queries at all?

* Are all tables included in the query correctly indexed. Clustered index on tables etc?
* Have you run your query through Execution Planner? Any areas that could be improved?
* Is only the data you need to update being updated?

You should definitely have a look at the source of the problem first and see if you can improve things here.


这篇关于如何避免[System.Data.SqlClient.SqlException] = {“超时已过期. &quot;}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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