All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
在ASP.NET2.0中创建Web应用程序主题_[Asp.Net教程]
SQL,Server之分布式事务_mssql学习_编程技术
XSL中实现HTML的表格自动换行_[XML教程]
.NET内置对象之Session对象_[Asp.Net教程]
PHP项目将联合起来转向PHP5_php资料_编程技术
PHP高亮显示,XML,源代码_php资料_编程技术
C#中提供的VB不支持的新特性_.net资料_编程技术
PHP实例:学习PHP程序对用户身份认证实现两种方法_[PHP教程]
。NET(C#)连接各类数据库集锦_[Asp.Net教程]
利用XMLHTTP无刷新自动实时更新数据_[XML教程]
Reading number is top 10 pictures
关于海盗的研究
Small QiShu -- ShuangShuangPan1
水晶头骨造型的酒瓶
A cat have life principles
Azusa Yamamoto1
Group of female porn in 《westwards》, uninhibited woman threatened to not the bottom line
非笑不可:最强爆笑图片精选
9.3阅兵全景图7-指挥系统和后勤保障系统梯队
赵惟依写真2
Female model behind the bitterness, often being overcharged4
Download software ranking
Unix video tutorial17
Visual C++界面编程技术
Tram sex maniac 2 (H) rar bag17
Dance with duck(male prostitution)
Unix video tutorial4
Sora aoi‘s film--Lust fan wall
Be there or be square
C#程序员参考手册
Unix video tutorial7
Tram sex maniac 2 (H) rar bag4
归海一刀 published in(发表于) 2014/2/1 0:23:46 Edit(编辑)
解决SqlTransaction用尽的问题(SQL处理超时)_[SQL,Server教程]

解决SqlTransaction用尽的问题(SQL处理超时)_[SQL,Server教程]

解决SqlTransaction用尽的问题(SQL处理超时)_[SQL Server教程]

有时候程序处理的数据量比较小时,四平八稳,一切安然无恙,但数据量一大,原先潜伏的问题就暴露无遗了。
原访问数据库的代码为:
1SqlConnection conn = new SqlConnection(strConn);
2conn.Open();
3SqlTransaction trans = conn.BeginTransaction();
4try
5{
6 CEngine.ExecuteNonQuery(trans,CommandType.Text,sql);
7 trans.Commit();
8}
9catch(SqlException ex)
10{
11 trans.Rollback();
12 ErrorCode = ex.Number;
13 Info = "数据操作失败:" + ex.Message;
14}
15finally
16{
17 trans.Dispose();
18 conn.Close();
19}
20
21
22
运行时,一旦出现数据量过大或者处理时间较长,则系统会提示出错。错误提示为“SqlTransaction已经用完;它再也不能使用。”


开始时,我怀疑是跟内存有关。因为系统需要做好事务回滚的准备,每执行一条插入或修改的SQL,都要有一定的开销,数据量一大,恐怕就吃不消了。不过我查了一下SQL SERVER的资料,未见提到内存的问题。
后来想到,数据库连接SqlTransaction有个时间问题。默认是15秒。数据量大的时候,这个时间很可能就不够了。于是改为:
1SqlConnection conn = new SqlConnection(strConn);
2conn.Open();
3SqlTransaction trans = conn.BeginTransaction();
4try
5{
6 SqlCommand cmd = new SqlCommand();
7 cmd.CommandType = CommandType.Text;
8 //连接时限改为300秒
9 cmd.CommandTimeout = 300;
10 cmd.CommandText = sql;
11 cmd.Connection = conn;
12 cmd.Transaction = trans;
13 cmd.ExecuteNonQuery();
14 trans.Commit();
15}
16catch(SqlException ex)
17{
18 trans.Rollback();
19 ErrorCode = ex.Number;
20 Info = "数据操作失败:" + ex.Message;
21}
22finally
23{
24 trans.Dispose();
25 conn.Close();
26}
修改后在测试,问题解决:)







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.