日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

NOCOUNT如何影响ADO.NET(SET NOCOUNT ON的性能问题)

發布時間:2025/3/19 asp.net 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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%

如果您也親自測試一下可以很明顯的發現:結果對于證明起到的作用很小。

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的NOCOUNT如何影响ADO.NET(SET NOCOUNT ON的性能问题)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。