Solved

Set Nocount On Too Slow

Posted on 2001-07-24
4
693 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Join & Write a Comment

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

771 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now