Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.【转】

时间:2023-01-10 10:46:28

今天碰到了一个查询异常问题,上网查了一下,感谢原创和译者

如果你使用的数据库连接类是 the Data Access Application Blocks "SqlHelper" 或者 SqlClient Class , 你在执行一个很费时的SQL 操作时候,可能就会碰到下面的超时异常。

---------------------------

---------------------------
Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.
---------------------------
OK   
---------------------------

你会说,我在连接字符串中已经 设置了 Connect Timeout=80000 ,并且数据库中超时连接也是设置的值是一个很大的值。为啥到了30秒,仍然超时了呢??

这是因为:
你的设置并没有问题,是你混淆了  SqlCommand.CommandTimeout  和 SqlConnection.ConnectionTimeout 这两个的区别了。
你的连接字符串中的超时只是设置的 SqlConnection.ConnectionTimeout 的值,而不是设置的 SqlCommand.CommandTimeout 的值。
SqlHelper 中并没有 SqlCommand.CommandTimeout 的相关设置。需要你自己设置。

下面是两个的比较:

SqlCommand.CommandTimeout
获取或设置在终止执行命令的尝试并生成错误之前的等待时间。
等待命令执行的时间(以秒为单位)。默认为 30 秒。

SqlConnection.ConnectionTimeout
获取在尝试建立连接时终止尝试并生成错误之前所等待的时间。
等待连接打开的时间(以秒为单位)。默认值为 15 秒。

一些更详细的对这个问题的描述看:
http://www.eggheadcafe.com/PrintSearchContent.asp?LINKID=357

这个问题可以算是 SqlHelper 设计的时候,一个考虑不周的地方吧。
SqlCommand.CommandTimeout 的默认值是30,对于我写的大多数程序来说,这个值足够了。所以一直都没有发现SqlHelper的这个问题。今天在查本地一台比较差的机子上生成一个超长帖子(近4000个回复)无响应的问题时候,才发现SQLHelper 存在的这个问题。

把command的Timeout属性设置一下就ok了!

Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.【转】 /// <summary>
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.【转】    /// 执行查询语句,返回DataTable
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.【转】    /// </summary>
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.【转】    /// <param name="SQLString">查询语句</param>
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.【转】    /// <param name="commTime">设置查询Timeout</param>
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.【转】    /// <returns>用于复杂查询</returns>
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.【转】    public static DataTable GetDataTable(string SQLString,int commTime)
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.【转】    {
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.【转】        string connectionString = System.Configuration.ConfigurationManager.AppSettings["connectionString"];
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.【转】        using (System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection(connectionString))
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.【转】        {
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.【转】            DataTable dt = new DataTable();
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.【转】            try
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.【转】            {
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.【转】                connection.Open();
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.【转】                System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter();
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.【转】                System.Data.SqlClient.SqlCommand comm = new System.Data.SqlClient.SqlCommand(SQLString, connection);
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.【转】                comm.CommandTimeout = commTime;
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.【转】                da.SelectCommand = comm;
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.【转】                da.Fill(dt);
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.【转】            }
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.【转】            catch (System.Data.SqlClient.SqlException ex)
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.【转】            {
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.【转】                throw new Exception(ex.Message);
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.【转】            }
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.【转】            return dt;
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.【转】        }
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.【转】    }

Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.【转】的更多相关文章

  1. Timeout expired&period; The timeout period elapsed prior to completion of the operation or the server is not responding&period;

    今天碰到了一个查询异常问题,上网查了一下,感谢原创和译者 如果你使用的数据库连接类是 the Data Access Application Blocks "SqlHelper" ...

  2. 记录一次在生成数据库服务器上出现The timeout period elapsed prior to completion of the operation or the server is not responding&period;和Exception has been thrown by the target of an invocation的解决办法

    记一次查询超时的解决方案The timeout period elapsed...... https://www.cnblogs.com/wyt007/p/9274613.html Exception ...

  3. 解决 Timeout expired&period; The timeout period elapsed prior to completion of the operation or the server is not responding&period; 的问题

    在web 网站开发中,经常需要连接数据库,有时候会出现这样的数据连接异常消息: 主要原因是 应用程序与数据库的连接超出了数据库连接的默认时长,在这种情况下,我们可以把数据库连接的时长延长一些,因为 C ...

  4. &lbrack;bug&rsqb;Timeout expired&period; The timeout period elapsed prior to completion of the operation or the server is not responding

    写在前面 在mysql中这个异常是非常常见的,超时分为连接超时和执行超时,而连接超时,大部分原因是网络问题,或客户端到服务端的端口问题造成. bug场景 有的时候,使用MySqlDataReader在 ...

  5. The timeout period elapsed prior to completion of the operation or the server is not responding&period;

    问题:更新数据的状态值时,部分报出如下异常: 即时有成功更新,时有报错问题出现. 在LOG中发现成功更新的数据,存在更新时间过长问题,将近30秒(EF默认的CommandTimeout为30秒): 代 ...

  6. SSRS 2008 R2 错误:Timeout expired&period; The timeout period

    今天遇到了Reporting Services(SQL SERVER 2008 R2)的报表执行异常情况,报表加载数据很长时间都没有响应,最后报"An error occurred with ...

  7. SQLSERVER:Timeout expired&period; The timeout period elapsed prior to obtaining a connection from the pool&period; This may have occurred because all pooled connections were in use and max pool size was reached&period;

    背景: 在最近开发中遇到一个问题,对一个数据库进行操作时,我采用64个并行的任务每个任务保证一个数据库连接对象:但是每个任务内部均包含有24个文件需要读取,在读取文件之后,我们需要快速将这24个文件批 ...

  8. Connection open error &period; Connection Timeout Expired&period; The timeout period elapsed during the post-login phase&period;

    是这样的,最近我在开发Api(重构),用的数据库是Sqlserver,使用的Orm是 SqlSugar(别问我为什么选这个,boss选的同时我也想支持国人写的东西,且文档也很全). 被催的是,写好了程 ...

  9. 网站错误记录:Timeout expired&period; The timeout period elapsed prior to obtaining a connection from the pool&period;

    今天看公司项目的错误日志文件,发现日志文件都是记录的这个错误. 经过网站查找,发现英文翻译是: 译:超时,与连接池的连接时间已过.这种情况发生是因为连接池在使用和最大连接池数目已满 通过翻译,可以看出 ...

随机推荐

  1. windows tomcat配置大全

    Tomcat下JSP.Servlet和JavaBean环境的配置 第一步:下载j2sdk和tomcat:到sun官方站点()下载j2sdk,注意下载版本为Windows Offline Install ...

  2. java实现给图片添加水印

    package michael.io.image; import java.awt.AlphaComposite; import java.awt.Graphics2D; import java.aw ...

  3. tmux的使用方法和个性化配置

    介绍 tmux是一个优秀的终端复用软件,即使非正常掉线,也能保证当前的任务运行,这一点对于远程SSH访问特别有用,网络不好的情况下仍然能保证工作现场不丢失!此外,tmux完全使用键盘控制窗口,实现窗口 ...

  4. ViewController

    ViewController ViewController 进入VC后先调用loadView,再调用ViewDidLoad ViewDidLoad皆为系统调用 需要先调用[super viewDidL ...

  5. 在centOS上搭建wordpress博客系统

    一.主要内容 1.安装LAMP服务器系统(Linux.Apache.MySQL.PHP ); 2.安装wordpress: 二.具体步骤 一.LAMP环境设置 1.安装LAMP系统,在centOS上可 ...

  6. 17秋 软件工程 团队第五次作业 Alpha Scrum1

    题目:团队作业--Alpha冲刺 17秋 软件工程 团队第五次作业 Alpha Scrum1 各个成员在 Alpha 阶段认领的任务 伟航:督促和监督团队进度,协调组内合作 港晨:APP前端页面编写: ...

  7. &lbrack;OpenCV&rsqb; Samples 16&colon; Decompose and Analyse RGB channels

    物体的颜色特征决定了灰度处理不是万能,对RGB分别处理具有相当的意义. #include <iostream> #include <stdio.h> #include &quo ...

  8. QT开发环境安装配置教程

    QT开发环境安装配置教程 分类: QT2012-11-29 23:31 35366人阅读 评论(12) 收藏 举报 Linux版的直接在ubutnu软件中心输入QT,安装响应的Designer,Cre ...

  9. ubuntu下如何批量修改文件后缀名

    正确的方法是: 在命令行中输入   rename   's/\.JPG/.jpg/'    *.JPG [注意] 在单引号中的最后一个'/'符号不能少! 意思是:把当前文件夹下的所有 .JPG文件 替 ...

  10. xgb 绘制

    1.windows安装Graphviz2.38 安装地址:https://graphviz.gitlab.io/_pages/Download/Download_windows.html 2.在pyt ...