Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Command Vs Connection Object

Author  Topic 

Tiwari
Starting Member

18 Posts

Posted - 2002-07-09 : 03:04:57
Which one will be faster or better. option1 or option2

dim cmd As ADODB.Command
dim g_connection as adodb.connection

option 1:

With cmd
.ActiveConnection = g_oconnection
.CommandText = Sql
.CommandType = adCmdText
.Execute
End With

Set cmd.ActiveConnection = Nothing


option 2:

g_connection.execute SQL

please mention the reason to make me more clear about using command object or connection directly.




LarsG
Constraint Violating Yak Guru

284 Posts

Posted - 2002-07-09 : 05:26:25
In general, it would not make much of a difference with regard to execution time I suppose. If you are interested, you should do a comparison as it may depend on what happens in your application.

There are some things that only can be done using a command object, e.g. handling output parameters. This may serve as an incitament to always use the command object as it would be easier to add parameter handling if you already have a command object.

If you are experiencing performance problems this is not the place to start looking. There are much more to be gained by looking over your queries, index strategy etc.



Go to Top of Page

Tiwari
Starting Member

18 Posts

Posted - 2002-07-09 : 06:23:16
Thanks for giving the valuable Information.

Go to Top of Page

MakeYourDaddyProud

184 Posts

Posted - 2002-07-09 : 06:40:32
Operationally, none. But there is a subtle difference in the semantics of the action that will be taken. With the first options, you are telling the Data Access provider information up front about the type of query you will be executing and you have the refinement in place to stipulate any restriction on the behavior prior to .EXECUTE. For instance, in your WITH...

cmd.CommandType = adExecuteNorecords tells the data provider no records are expected from the result.

cmd.CommandType = adCmdStoredProc tells the provider an SP is to be executed. This will optimise the .EXECUTE action for the query.

HTH

Daniel Small MIAP
www.danielsmall.com IT Factoring
Go to Top of Page

KHeon
Posting Yak Master

135 Posts

Posted - 2002-07-09 : 07:29:17
While your code looks to be straight VB, in ASP (VBScript) Option 2 would be the better choice because you are not having to create two objects to accomplish one task. In VB it's not as simple as that though, while object creation is the more slower approach, it's hard to get away from creating and using objects. In ASP though it's critical that you try and streamline this sort of thing because each call to Server.CreateObject is slow (relative to everything else). This is primarily because Server.CreateObject is an interface to CreateObject.

I agree with the above comments, you need to do testing in order to find out what works best in YOUR situation. Every project and environment will be different and will force different approaches.

Thanks, and good luck.

Kyle Heon
PixelMEDIA, Inc.
Senior Application Programmer, MCP
kheon@pixelmedia.com
Go to Top of Page
   

- Advertisement -