Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Set Nocount On Too Slow

Posted on 2001-07-24
4
Medium Priority
?
723 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 200 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
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 shrink a transaction log file down to a reasonable size.

885 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