Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Set Nocount On Too Slow

Posted on 2001-07-24
4
Medium Priority
?
717 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

670 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