使用 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 转化时 ...
随机推荐
- mybatis 调用mysql存储过程 带输出输入参数
http://lohasle.iteye.com/blog/1669879 存储过程都是一样的,只是根据自己的喜好,可以用MAP或者JAVABEAN传递参数. -- ----------------- ...
- POJ 3468 A Simple Problem with Integers //线段树的成段更新
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 59046 ...
- 【Android 应用开发】 ActionBar 样式详解 -- 样式 主题 简介 Actionbar 的 icon logo 标题 菜单样式修改
作者 : 万境绝尘 (octopus_truth@163.com) 转载请著名出处 : http://blog.csdn.net/shulianghan/article/details/3926916 ...
- using 关键字给类和名称空间指定别名
1. using System; using System.Text; namespace DLL { public class Class1 { public void showStr() { Co ...
- Android-隐式Intent
隐式Intent表示不具体明确要打开的activity,利用隐式intent我们可以打开其他应用. 一个隐式intent的主要组成部分: 1.action 要执行的操作. 通常以intent类的常量表 ...
- AngularJs练习Demo7
@{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name="viewport&quo ...
- ifstream中文路径问题分析
最近维护一个项目,遇到了ifstream在中文路径下打开文件失败的bug,我搜索了一下,最后整理成下文以后日后查阅. 一.问题重现 vs2008下创建一个简单win32工程. 使用ANSI编码方式:项 ...
- hdfs-over-ftp安装与配置
hdfs-over-ftp是一个开源,简单易用的实现了对HDFS系统的下载和上传功能的小工具.可以作为管理工具来使用,快捷方便. 1 安装jdk(1.6以上版本)并配置环境变量分别执行java -ve ...
- PHP连接Microsoft SQL Server 2005/2008
PHP自带的MSSQL扩展php_mssql.dll原来是给SQL Server 2000用的,难怪连接不上2008?! -_-!!要使用SQL Server 2005以上版本,就要用到微软为PHP提 ...
- jQuery读取json文件,实现省市区/县(国标)三级联动
最近做一个微信项目,需要用户填写所在的省市区/县,决定使用jQuery读取json文件来实现省市区/县的联动. 其实很简单,jQuery文档也有详细解释: 代码如下: html <table w ...