Solved

Set Nocount On Too Slow

Posted on 2001-07-24
4
701 Views
Last Modified: 2009-07-29
Hi, I did some performance testing through VB6 and ADO 2.5 to see if running the following code

rs.Open "set nocount on", conn
(where rs is a recordset and conn is the current connection string)

would be faster or slower than not using it at all.  Altough books online says less network traffic results from this, it is around 10% slower.  Is this true?  I duplicated these results by running straight from Query Analyzer.  

Is there anyway to use "Set Nocount ON" and get better performance?

Here's the entire code
------------------------------------------
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset, rs2 As New ADODB.Recordset
   
conn.Open "provider=sqloledb.1;data source=sqlname;user id=name;password=;initial catalog =testDB"
rs.Open "set nocount on", conn
rs.Open "select * from testtable where itemid = '8103'", conn, adOpenDynamic, adLockBatchOptimistic, adCmdText
Set rs = Nothing
Set conn = Nothing
-----------------------------------------

Thanks.
0
Comment
Question by:kweckwerth
  • 2
  • 2
4 Comments
 
LVL 18

Accepted Solution

by:
nigelrivett earned 50 total points
ID: 6315756
Doing it this way you have an extra db access which means a lot more network trafffic. It gives you a gain if you use this in a stored proc. You will gain more in not having to compile the sql at run time, abstract the database structure (giving more flexibility) and be more secure too.

create procedure spTest
as
set nocount on
select * from testtable where itemid = '8103'
go

you should find this a lot faster.
0
 
LVL 18

Expert Comment

by:nigelrivett
ID: 6315759
Oh and you were trying to create a recordset when no data was returned. An exec would have been faster than an open.
This is also the case when calling SPs that don't return recordsets.
0
 

Author Comment

by:kweckwerth
ID: 6319211
nigelrivett, I am passing a parameter via
"comm.Parameters.Append comm.CreateParameter("@id", adVarChar, adParamInput, 55, "8103")" in addition to the above code.

Do you mean a command.execute?  How do you return all fields using a command object other than specifically declaring all the fields?

Thanks.


0
 

Author Comment

by:kweckwerth
ID: 6319217
Thanks.  I found that all the time was in creating the connection and not focusing on the sproc.  I found a %.5 improvement by using "set nocount on".

Better than nothing but it may be the sproc as well.

0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question