473,394 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Execute method vs Recordset object

Why would you use the Recordset object over the Execute method of
getting data from your Sql database.

For example, I have the following:

Execute Method
************************************************** *************
Set connectionToDatabase=Server.CreateObject("ADODB.Co nnection")
connectionToDatabase.ConnectionTimeout = 60
connectionToDatabase.Open "DSN=Customer;user id=SA;password="

Set RecordCollection=connectionToDatabase.Execute("Sel ect * from Customers")
************************************************** *************

************************************************** *************
Set connectionToDatabase=Server.CreateObject("ADODB.Co nnection")
connectionToDatabase.ConnectionTimeout = 60
connectionToDatabase.Open "DSN=Customer;user id=SA;password="

Set RecordCollection=Server.CreateObject("ADODB.Record set")
recordCollection.Open "Select * from Customers",connectionToDatabase
************************************************** *************

They both seem to work about the same. Why is one better than the other?

In the Execute method you just do a connection and select in one statement.

In the Recordset method, you have to create the object and then do a
connect and select.

Thanks,

Tom

Jul 19 '05 #1
4 5020
Some pros and cons here, mostly cons of using ADODB.Recordset

http://www.aspfaq.com/2191

I prefer the connection object alone; in just about every case where one
might say, "you HAVE to use ADODB.Recordset property for this," I have found
or developed a better solution without using it...

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


"Thomas Scheiderich" <tf*@deltanet.com> wrote in message
news:40**************@deltanet.com...
Why would you use the Recordset object over the Execute method of
getting data from your Sql database.

For example, I have the following:

Execute Method
************************************************** *************
Set connectionToDatabase=Server.CreateObject("ADODB.Co nnection")
connectionToDatabase.ConnectionTimeout = 60
connectionToDatabase.Open "DSN=Customer;user id=SA;password="

Set RecordCollection=connectionToDatabase.Execute("Sel ect * from Customers") ************************************************** *************

************************************************** *************
Set connectionToDatabase=Server.CreateObject("ADODB.Co nnection")
connectionToDatabase.ConnectionTimeout = 60
connectionToDatabase.Open "DSN=Customer;user id=SA;password="

Set RecordCollection=Server.CreateObject("ADODB.Record set")
recordCollection.Open "Select * from Customers",connectionToDatabase
************************************************** *************

They both seem to work about the same. Why is one better than the other?

In the Execute method you just do a connection and select in one statement.
In the Recordset method, you have to create the object and then do a
connect and select.

Thanks,

Tom

Jul 19 '05 #2
Using the recordset object allows you to get a 'Disconnected Recordset'
which is the 'preferred' method if you are looking for maximum scaleability.
A disconnected recordset does not hold expensive connections to the database
except during retrieval of the data and updating of new data back to the
server (see BatchUpdate).

http://www.4guysfromrolla.com/webtech/080101-1.shtml

However, there are times (for example when wanting to work with a large
recordset) that a standard server-side cursor - thus a fully connected
recordset - is beneficial since the requirement of a disconnected recordset
is that *all* the data be retrieved to the client in one go. A server-side
cursor only retrieves each record as navigated.

So .. pros and cons.

I have a VB class that returns disconnected recordsets and I generally try
and ensure that each recordset is as small as possible. Even for looping
through large datasets I can generally retrieve a recordset of the record
IDs required and then do individual requests and updates for each record
identified.

Chris Barber.

"Thomas Scheiderich" <tf*@deltanet.com> wrote in message
news:40**************@deltanet.com...
Why would you use the Recordset object over the Execute method of
getting data from your Sql database.

For example, I have the following:

Execute Method
************************************************** *************
Set connectionToDatabase=Server.CreateObject("ADODB.Co nnection")
connectionToDatabase.ConnectionTimeout = 60
connectionToDatabase.Open "DSN=Customer;user id=SA;password="

Set RecordCollection=connectionToDatabase.Execute("Sel ect * from Customers")
************************************************** *************

************************************************** *************
Set connectionToDatabase=Server.CreateObject("ADODB.Co nnection")
connectionToDatabase.ConnectionTimeout = 60
connectionToDatabase.Open "DSN=Customer;user id=SA;password="

Set RecordCollection=Server.CreateObject("ADODB.Record set")
recordCollection.Open "Select * from Customers",connectionToDatabase
************************************************** *************

They both seem to work about the same. Why is one better than the other?

In the Execute method you just do a connection and select in one statement.

In the Recordset method, you have to create the object and then do a
connect and select.

Thanks,

Tom
Jul 19 '05 #3
Also, a disconnected recordset can be passed to remote clients to use (eg.
cache) and either throwaway or return with updates. A classic example is
putting it into an MSMQ message to a remote laptop machine that may be
offline for a day or so. When it returns it can send that same (persisted to
disk as XML as presume) recordset back to the DB to update the entries. If
any records fail to update (eg. deleted in the interim) then each records
'status' can be interrogated to see why it failed thus allowing the app /
user to make a decision about what to do.

Very groovy and to some extent the 'defacto' standard preferred by Microsoft
for large scale database applications with lots of potential concurrency of
connections (because of the minimal time that a connection is held to the
DB). There is nor real degradation in performance for this connect and
reconnect scenario as long as connection pooling becomes activated
(reconnects are simply provided from the pool and are almost instantaneous).

Chris.

"Thomas Scheiderich" <tf*@deltanet.com> wrote in message
news:40**************@deltanet.com...
Why would you use the Recordset object over the Execute method of
getting data from your Sql database.

For example, I have the following:

Execute Method
************************************************** *************
Set connectionToDatabase=Server.CreateObject("ADODB.Co nnection")
connectionToDatabase.ConnectionTimeout = 60
connectionToDatabase.Open "DSN=Customer;user id=SA;password="

Set RecordCollection=connectionToDatabase.Execute("Sel ect * from Customers")
************************************************** *************

************************************************** *************
Set connectionToDatabase=Server.CreateObject("ADODB.Co nnection")
connectionToDatabase.ConnectionTimeout = 60
connectionToDatabase.Open "DSN=Customer;user id=SA;password="

Set RecordCollection=Server.CreateObject("ADODB.Record set")
recordCollection.Open "Select * from Customers",connectionToDatabase
************************************************** *************

They both seem to work about the same. Why is one better than the other?

In the Execute method you just do a connection and select in one statement.

In the Recordset method, you have to create the object and then do a
connect and select.

Thanks,

Tom
Jul 19 '05 #4
Thomas Scheiderich wrote:
Why would you use the Recordset object over the Execute method of
getting data from your Sql database.


You are ALWAYS using a recordset object, even if you don't create one
explicitly. When Execute is used, a recordset object with the default
property settings is created implicitly (behind the scenes). The default
property settings are:

CursorLocation = adUseServer (server-side)
CursorType = adOpenForwardOnly (forward-only - non-scrollable)

According to the documentation:
LockType = adLockReadOnly
but in my experience, this does not appear to be true. It's irrelevant since
I rarely need to make updates to my recordsets, using them only to retrieve
data for display purposes.

If you need any other settings for these or any other recordset properties
(which should be very rare in asp, if you are using good programming
practices) then you need to explicitly create the recordset object yourself
and set the properties. then use Open to open it (if you use Execute, your
carefully created object will NOT get used).

In addition, if you wish to use the "stored-procedure-as-connection-method"
technique to execute a stored procedure, then you need to create the
recordset object explicitly:
set rs=createobject("adodb.recordset")
cn.storedprocedurename param1,...,parmN, rs

HTH,
Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jill Graham | last post by:
Hi, I'm using an access database and found following problem : I have a table X with 2 records : record 1 & record 2. I execute following procedure with 2 steps : 1. The procedure deletes...
5
by: shank | last post by:
Can anyone give me some general ideas on why an error like Object doesn't support this property or method: 'ZoneRS.MoveFirst' comes up on a page? MoveFirst is a command to move to the first...
2
by: Matt | last post by:
I want to exexute stored procedure in ASP, but it has error "Microsoft VBScript compilation (0x800A0401) Expected end of statement" on line (1). The stored procedure "sp_emp" contain "select *...
2
by: michaaal | last post by:
I feel a bit silly asking this because I use this code all the time, but what does the ",,129" mean? Are there other parameters that one might use (I only do fairly simple SQL commands). ...
18
by: Darryl Kerkeslager | last post by:
When I open an ADO Recordset, I close it. However, it seems that there may be some difference in this manner of opening a Recordset: Dim rL As ADODB.Recordset Set rL = New ADODB.Recordset ...
1
by: sjallard | last post by:
Hi, I'd like to do something like that (see explanations after the code snippet) : Sub mainSub (foo as String) Dim msScript As New ScriptControl msScript.Language = "VBScript" Dim someVar...
2
by: rn5a | last post by:
In a ASP applicatiuon, the FOrm has a textbox & a select list where the admin can select multiple options. Basically the admin has to enter the name of a new coach in the textbox & select the...
0
ADezii
by: ADezii | last post by:
When you create an ADO Recordset, you should have some idea as to what functionality the Recordset does/does not provide. Some critical questions may, and should, be: Can I add New Records to the...
1
by: mikegolden | last post by:
An application I'm working on makes extensive use of output parameters and return values, thus forcing me to use the ADODB Command object to execute the stored procs. For recordset returning stored...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.