About the performance of set Nocount on |c# The return value of the call stored procedure is always-1

Source: Internet
Author: User
Tags management studio

Perhaps because it is too simple, you have not been able to pay attention to this statement, just remember "just" to improve the performance of the point. Sometimes you write a few sentences in the stored procedure, and sometimes you are too lazy to knock on the letters. But How much difference do they have between set NOCOUNT on and set NOCOUNT OFF? The day before yesterday was curious. Finally trying to figure out how much difference they have between performance. In Google again, found a few articles. We can draw some conclusions.

How NOCOUNT affects ADO. NET (nocount Impact on ADO) by Jon Galloway
In the article comments there is a test code that you can copy to the Query Analyzer for testing. Basically, SET NOCOUNT on is faster than off (but the result of my test is not very good, basically the difference is not too big, more exaggerated is the article below the comment:
I want to share my experience with NOCOUNT.
A stored procedure who joins a few tables with more than 100.000 rows are very slow if you run it with ADO and with an opt Ion NOCOUNT on. By setting NOCOUNT OFF the same procedure would be a times faster.
There is no difference if you execute this procedure from the Management Studio with NOCOUNT OFF or on
MY god!
Seeing is believing

Basically, they conclude that using NOCOUNT can reduce the transmission of the network. When we set NOCOUNT on, the stored procedure executes every SQL statement (likeSELECT, INSERT, UPDATE, DELETE) is ignored when sending a DONE_IN_PROC message to the client .
The easiest way to determine if update data is successful is ExecuteNonQuery () >0. When using set NOCOUNT on,ExecuteNonQuery always returns-1. a good solution is to use the Out parameter method to output whether it uses the rows affected result to determine if the update succeeded.

In addition, there is a T-SQL coding Standard is a good article. Well worth a read.

Original address: http://www.cnblogs.com/cnzc/archive/2007/09/01/878434.html

--------------------------------------------------------------------------

public virtual int Getmenubyrid (nullable<int> RID)
{
var ridparameter = Rid.hasvalue?
New ObjectParameter ("RID", RID):
New ObjectParameter ("RID", typeof (int));

Return ((Iobjectcontextadapter) this). Objectcontext.executefunction ("Getmenubyrid", Ridparameter);
}

Objectcontext.executefunction This return is the number of rows affected

About the performance of set Nocount on |c# The return value of the call stored procedure is always-1

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.