维生素C.net
Talents come from diligence, and knowledge is gained by accumulation 天才源于勤奋,知识源于积累。
难忘的1654天
博客园  首页  新随笔  新文章  联系  管理  订阅 订阅
随笔- 220  文章- 1  评论- 1659 
NOCOUNT如何影响ADO.NET(SET NOCOUNT ON的性能问题)

How NOCOUNT affects ADO.NET一文中提到:

Previously, in Classic ASP and ADO, NOCOUNT was most commonly a factor if you were checking RecordsAffected on Command.Execute(). SqlDataReader does have a RecordsAffected property, but it's rarely used since it's not populated until the datareader has iterated all the rows and the datareader is closed. There are some possible implications if you're using DataAdapters to submit changes to the database, since it uses the rows affected result to determine if the update succeeded. Probably the easiest way to check for that case is to search the codebase for SqlDataAdapter and see if the Update() method is being called.

还有:

Tech notes if you're interested in tracing how RecordsAffected is set and used by pointing Reflector at System.Data:
System.Data.SqlClient.TdsParser.ProcessDone() sets RecordsAffected.
System.Data.Common.DbDataAdapter.UpdateRow() uses reader.RecordsAffected in determining whether to call AcceptChanges and ApplyToDataRow.

保险一点来说,通过作者所说的调用Update()来做判断似乎并不可靠,中间有很多步骤都有可能出问题从而影响最终的结果。同时,debug起来的也有麻烦了,嵌入sql debug后对于调试程序很有用,而如果按作者所说这个debug的功能都被削减了。又把database和application给分开调了。

评论中有人写了一个简单的测试程序,并给出了他的测试结果,他认为还是SET NOCOUNT ON快。

测试使用的存储过程
DECLARE @Start DATETIME, @End DATETIME, @Counter INT, @NoCountOff INT, @NoCountOn INT

CREATE TABLE #MyTable (

Id 
INT NOT NULL IDENTITY(1,1) PRIMARY KEY

, FirstName 
VARCHAR(128) NOT NULL

, LastName 
VARCHAR(128) NOT NULL

)

SET NOCOUNT OFF

SET @Counter = 1

SET @Start = GETDATE()

WHILE @Counter <= 150000

BEGIN

INSERT #MyTable (FirstName, LastName) VALUES ('Scott', 'Whigham')

SET @Counter = @Counter + 1

END

SET @End = GETDATE()

SELECT @NoCountOff = DATEDIFF(ms, @Start, @End)

SET NOCOUNT ON

SET @Counter = 1

SET @Start = GETDATE()

WHILE @Counter <= 150000

BEGIN

INSERT #MyTable (FirstName, LastName) VALUES ('Scott', 'Whigham')

SET @Counter = @Counter + 1

END

SET @End = GETDATE()

SELECT @NoCountOn = DATEDIFF(ms, @Start, @End)

SELECT @NoCountOff AS 'NoCountOff', @NoCountOn AS 'NoCountOn', COUNT(*) AS NumberOfRows FROM #MyTable

DROP TABLE #MyTable


我与他测试的环境不同,在xp + SQL 2005 Ent with SP1上测试的,结果结论相反,把结果数据也share给大家:

NoCountOff   |   NoCountOn | xRate

7106    5893    20.58%
6156    6890    -10.61%
7093    7343    -3.41%
5780    6406    -9.77%
5563    6860    -18.91%
5610    7390    -24.09%
5810    6923    -21.38%
6296    7436    -15.33%

-- insert 1
46    0
16    0
0    0
0    0
16    0

-- insert 1000
420     393     6.88%
423     390     8.47%
966     423     128.37%

-- insert 100,000
43250    42860    0.91%

-- delete all then insert 100,000
42076    39826    5.65%

如果您也亲自测试一下可以很明显的发现:结果对于证明起到的作用很小。

0
0
0
(请您对文章做出评价)
« 上一篇:从清理目录想到的
» 下一篇:Inbox.com使用的asp.net和ajax技术
posted on 2006-09-05 16:19 维生素C.NET 阅读(1724) 评论(0)  编辑 收藏 所属分类: ASP.NET
注册用户登录后才能发表评论,请 登录 或 注册 。
博客园首页  IT新闻  闪存  知识库  招聘
找优秀程序员,就在博客园
IT新闻:
· Chrome的书签管理器即将升级
· Palm目标股价被降至0美元 或难免被收购
· 惠普可卷折柔性显示屏展示
· Intel年底发布USB 3.0控制器 暂无原生支持
· 德科学家用网络控制机器人探测海底世界
每天10分钟,轻松学英语
专题:Android  iPad  jQuery  Windows 7
推荐职位:
网站导航:
博客园首页  IT新闻  个人主页  闪存  程序员招聘  社区  博问  网摘

China-pub 计算机图书网上专卖店!6.5万品种2-8折!
China-Pub 计算机绝版图书按需印刷服务

相关搜索:
ASP.NET

在知识库中查看:
NOCOUNT如何影响ADO.NET(SET NOCOUNT ON的性能问题)



公告

view my mvp profile 看看有多少人来访问我的Blog了!
hotmail

我的主页  个人资料
我的闪存  发短消息
<2006年9月>
日一二三四五六
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

搜索

 
 

常用链接

  • 我的随笔
  • 我的空间
  • 我的短信
  • 我的评论
  • 更多链接
  • 我的参与
  • 我的新闻
  • 最新评论
  • 我的标签

我参与的团队

  • .NET新手training活动(0/0)
  • 北京.NET俱乐部(0/0)
  • 烟台.NET俱乐部(0/0)
  • ASP.NET AJAX (Atlas)学习(0/0)
  • MVP(微软最有价值专家)团队(0/0)
  • 博客园培训团队(0/0)
  • Silverlight学习与研究(0/0)
  • CLR基础研究团队(0/0)

随笔分类(148)

  • ASP.NET(26)
  • Code Warehouse(20)
  • IronRuby,DLR(2)
  • LINQ(3)
  • Reading(3)
  • Training@cnblogs(23)
  • Ubuntu(4)
  • Windows Live(6)
  • Windows Mobile(7)
  • XHTML & Web Standard(54)

随笔档案(220)

  • 2008年3月 (2)
  • 2008年1月 (3)
  • 2007年12月 (3)
  • 2007年9月 (1)
  • 2007年8月 (2)
  • 2007年7月 (3)
  • 2007年6月 (3)
  • 2007年3月 (4)
  • 2007年2月 (3)
  • 2007年1月 (1)
  • 2006年12月 (1)
  • 2006年11月 (8)
  • 2006年10月 (6)
  • 2006年9月 (11)
  • 2006年8月 (5)
  • 2006年7月 (4)
  • 2006年6月 (1)
  • 2006年5月 (10)
  • 2006年4月 (8)
  • 2006年2月 (2)
  • 2006年1月 (1)
  • 2005年12月 (11)
  • 2005年11月 (13)
  • 2005年10月 (3)
  • 2005年9月 (1)
  • 2005年8月 (4)
  • 2005年7月 (3)
  • 2005年6月 (4)
  • 2005年4月 (5)
  • 2005年3月 (10)
  • 2005年2月 (7)
  • 2005年1月 (28)
  • 2004年12月 (15)
  • 2004年11月 (10)
  • 2004年10月 (5)
  • 2004年9月 (1)
  • 2004年6月 (13)
  • 2004年5月 (5)

文章档案(1)

  • 2005年5月 (1)

相册

  • ASPNET2tutorial
  • BlogUsing
  • My love and my friends
  • newGallery
  • 下一代网络图片

.net网站收藏

  • ASP.NET2.0 Tutorial
  • CodeBetter.com
  • F#
  • IIS.net
  • MS NewsGroup
  • NewsGroups
  • OnlyVC.org
  • VWD2005GuidedTour
  • ZDNet China软件技术专区

OSS 2007

  • Charsh
  • Kaneboy
  • Official Team Blog

Python

  • BeginnersGuide

好友的BLOG

  • DemoFox@JoyCode
  • DflyingChen
  • dudu
  • EricLee
  • hbifts
  • idior
  • Jesee Qing
  • Lion
  • Rickie
  • Samuel
  • Steph`s Website
  • 翱翔.Net
  • 陈敬熙
  • 发条木偶
  • 葛涵涛
  • 古道风
  • 寒枫天伤
  • 老猫の理想
  • 刘老师
  • 刘彦博
  • 吕震宇
  • 木野狐
  • 佘广
  • 王sir
  • 小涛
  • 小新
  • 肖老师
  • 旋哥

积分与排名

  • 积分 - 427560
  • 排名 - 102

最新评论

  • 1. Re:http的基础知识帮助减少代码量和复杂度的一个Demo
  • 不知道说的啥
  • --YJJ
  • 2. re: 结构体,值类型和接口
  • <a title="不锈钢无缝管" href=" <a title="304不锈钢管价格" href=" <a tit...
  • --站
  • 3. re: 结构体,值类型和接口
  • <a href=" target="_blank">不锈钢管</a> <a href=" target="_blank...
  • --无缝不锈钢管
  • 4. re: 结构体,值类型和接口
  • <a href=" <a href=" ...
  • --无缝不锈钢管
  • 5. re: 结构体,值类型和接口
  • <a href=" target="_blank">不锈钢管</a> <a href=" target="_blank...
  • --无缝不锈钢管

阅读排行榜

  • 1. 英文名字及含义(29974)
  • 2. SQL Server 2005 Remote Access(16162)
  • 3. Visual Studio 2005 Team Edition和SQL Server 2005的下载(15343)
  • 4. ASP.NET SESSION的使用及原理(14947)
  • 5. Windows Installer 3.1(11797)

评论排行榜

  • 1. .NET Beginner Training Step by Step开始启动(320)
  • 2. Windows Live Messenger 8.0 Beta 的邀请(100)
  • 3. 加入[ 下一代网络web技术(Next Generation Web Application)团队Blog ](93)
  • 4. 博客园新手.net技术培训活动(55)
  • 5. 为什么在vista上做开发?(54)
Copyright ©2010 维生素C.NET