Solved

Set Nocount On Too Slow

Posted on 2001-07-24
4
713 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 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

630 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