使用 Microsoft.ApplicationBlocks.Data SqlHelper 查询超时以及解决方案
提示: 后面附有文件,不喜欢看吐槽的,直接到文章结尾下载
摘要:Data Access Application Block 是一个 .NET 组件,包含优化的数据访问代码,可以帮助用户调用存储过程以及向 SQL Server 数据库发出 SQL 文本命令。它返回 SqlDataReader、DataSet 和 XmlReader 对象。您可以在自己的 .NET 应用程序中将其作为构造块来使用,以减少需要创建、测试和维护的自定义代码的数量。您可以下载完整的 C# 和 Visual Basic .NET 源代码以及综合文档。【这段是抄的】
故事:
最近在项目中使用到了这个古老的组件,一切都是那么的美好,只到昨天下午,当我用这个组件执行一个时间比较长的存储过程时,厄运就来了:
try
{
SqlHelper.ExecuteNonQuery(connectionString, CommandType.StoredProcedure, sql);
return ;
}
catch (Exception ex)
{
return -;
}
每当执行一段时间,自动就抛出Timeout的异常,好吧,作为一个有理智的程序员,马上就去找怎么给SqlHelper中的查询自定义Timeout,然而……悲催的我竟然没有找到,好吧,拿出反编译工具看看有没有Timeout字段,依然没有
那么只能借助网络去找答案了,某度 呵呵,大量的转载,特意在搜索中加入了“Timeout” “超时” ,然并卵,万能的过滤大发,把那些词都忽略了。
再想想 google 哎…… 后来只能通过一些国内的“谷粉搜搜”之类的找一找了,虽然不多但还是找到了,都是E文的,然后借助自己很渣的E温水瓶,成功没找到答案。
好吧那只能看看有没有源代码了,某度照样渣,最后在一个外国网站上还真找到了源代码,然后简单修改
/// <summary>
/// This method opens (if necessary) and assigns a connection, transaction, command type and parameters
/// to the provided command.
/// </summary>
/// <param name="command">the SqlCommand to be prepared</param>
/// <param name="connection">a valid SqlConnection, on which to execute this command</param>
/// <param name="transaction">a valid SqlTransaction, or 'null'</param>
/// <param name="commandType">the CommandType (stored procedure, text, etc.)</param>
/// <param name="commandText">the stored procedure name or T-SQL command</param>
/// <param name="commandParameters">an array of SqlParameters to be associated with the command or 'null' if no parameters are required</param>
private static void PrepareCommand(SqlCommand command, SqlConnection connection, SqlTransaction transaction, CommandType commandType, string commandText, SqlParameter[] commandParameters)
{
//if the provided connection is not open, we will open it
if (connection.State != ConnectionState.Open)
{
connection.Open();
} command.CommandTimeout = Timeout;//注意这里是我加的
//associate the connection with the command
command.Connection = connection; //set the command text (stored procedure name or SQL statement)
command.CommandText = commandText; //if we were provided a transaction, assign it.
if (transaction != null)
{
command.Transaction = transaction;
} //set the command type
command.CommandType = commandType; //attach the command parameters if they are provided
if (commandParameters != null)
{
AttachParameters(command, commandParameters);
} return;
}
编译,引用,成功执行,一切又是那么的美好。

好吧,故事就到这了,特地把文件分享出来,毕竟助人为快乐之本,
里面有加入了Timeout字段并编译好的文件和 源码安装文件(未修改)
http://files.cnblogs.com/files/twzy/Microsoft.ApplicationBlocks.Data.zip
最后宣传一下自己的抓包软件
NetAnalzyer交流群:39753670 (PS 只提供交流平台,群主基本不说话^_^)
[转载请保留作者信息 作者:冯天文 网址:http://www.cnblogs.com/twzy/p/4976867.html]
使用 Microsoft.ApplicationBlocks.Data SqlHelper 查询超时以及解决方案的更多相关文章
- 记一次查询超时的解决方案The timeout period elapsed......
问题描述 在数据库中执行查询语句,大约1秒钟查询出来,在C#中用ado进行连接查询,一直等待很久未查出结果,最后抛出查询超时异常. 异常内容如下: Execution Timeout Expired. ...
- 1125MySQL Sending data导致查询很慢的问题详细分析
-- 问题1 tablename使用主键索引反而比idx_ref_id慢的原因EXPLAIN SELECT SQL_NO_CACHE COUNT(id) FROM dbname.tbname FORC ...
- 使用Spring访问Mongodb的方法大全——Spring Data MongoDB查询指南
1.概述 Spring Data MongoDB 是Spring框架访问mongodb的神器,借助它可以非常方便的读写mongo库.本文介绍使用Spring Data MongoDB来访问mongod ...
- SQL Server 页面查询超时(SOS_SCHEDULER_YIELD等待)
一.问题概述 问题大概是这样的,有一个功能页面经常查询超时,有时候就算能查询出来也要很长的时间,但是有时又会很快.遇到的这种问题在排除掉网络原因之后基本上可以从查询语句上去找原因. 编译查询SQL语句 ...
- MySQL Sending data导致查询很慢的问题详细分析【转载】
转自http://blog.csdn.net/yunhua_lee/article/details/8573621 [问题现象] 使用sphinx支持倒排索引,但sphinx从mysql查询源数据的时 ...
- Confluence 6 配置数据库查询超时时间
如果数据库的查询时间太长同时你的应用程序显示没有响应,你可以配置数据库的查询超时时间.在默认情况下 Confluence 没有超时时间.希望配置数据库查询超时时间,在你的测试服务器上进行下面的操作: ...
- 【HANA系列】SAP HANA XS使用Data Services查询CDS实体【二】
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[HANA系列]SAP HANA XS使用Dat ...
- 【HANA系列】SAP HANA XS使用Data Services查询CDS实体【一】
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[HANA系列]SAP HANA XS使用Dat ...
- spring data jpa查询部分字段、多余附加字段
spring data jpa查询部分字段 第一种方法:使用 model 查询时转化 首先建立一个 model ,写上自己想要查询的字段,然后写上构造函数,这步很重要,因为spring jpa 转化时 ...
随机推荐
- Laravel-表单篇-零散信息
1.asset('path'):用于引入静态文件,包括css.js.img 2.分页,调用模型的paginate(每页显示的行数)方法, 如$student = Student::paginate(2 ...
- dom4j解析接口使用SOAP传递的xml
xml 文件的格式类型: <?xml version="1.0" encoding="utf-8"?> <SOAP-ENV:Envelope ...
- Android TextView中实现点击文本超链接(无下划线)的封装类
android中有的时候须要在TextView上设置一些超链接,点击这些超链接时进行一些操作.比如新浪微博上的一些keyword,点击时会跳转到对应的页面. 怎样实现我们就直接看源代码吧. /** * ...
- oracle 格式化数字 to_char
转:http://blog.csdn.net/chinarenzhou/article/details/5748965 Postgres 格式化函数提供一套有效的工具用于把各种数据类型(日期/时间,i ...
- hdu2767 Proving Equivalences --- 强连通
给一个图,问至少加入�多少条有向边能够使图变成强连通的. 原图是有环的,缩点建图,在该DAG图上我们能够发现,要使该图变成强连通图必须连成环 而加入�最少的边连成环,就是把图上入度为0和出度为0的点连 ...
- samba错误
1.session setup failed: NT_STATUS_LOGON_FAILURE 该错误表示用户有误, 可能是用户不存在, 也有可能是密码错误, 或者用户只是在samba和系统的用户中的 ...
- tomcat配置数据源
1.修改conf下的context.xml,在<context>标签中添加: <Resource name="jdbc/soa" auth="Conta ...
- DEV LookUpEdit 使用方法
public class field { public string Name { get; set; } public string Explain { get; set; } } List< ...
- Winform 无边框随意拖动【转载】
本篇技术内容转载自:http://www.cnblogs.com/ap0606122/archive/2012/10/23/2734964.html using System; using Syste ...
- 由MyEclipse内存不足谈谈JVM内存设置
转自:http://www.javatang.com/archives/2007/12/03/1653250.html 如果没有进行设置的话,在使用MyEclipse的经常出现如下图所示内存不足的提示 ...