473,765 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 connectionToDat abase=Server.Cr eateObject("ADO DB.Connection")
connectionToDat abase.Connectio nTimeout = 60
connectionToDat abase.Open "DSN=Customer;u ser id=SA;password= "

Set RecordCollectio n=connectionToD atabase.Execute ("Select * from Customers")
*************** *************** *************** *************** ***

*************** *************** *************** *************** ***
Set connectionToDat abase=Server.Cr eateObject("ADO DB.Connection")
connectionToDat abase.Connectio nTimeout = 60
connectionToDat abase.Open "DSN=Customer;u ser id=SA;password= "

Set RecordCollectio n=Server.Create Object("ADODB.R ecordset")
recordCollectio n.Open "Select * from Customers",conn ectionToDatabas e
*************** *************** *************** *************** ***

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 5059
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.c om> 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 connectionToDat abase=Server.Cr eateObject("ADO DB.Connection")
connectionToDat abase.Connectio nTimeout = 60
connectionToDat abase.Open "DSN=Customer;u ser id=SA;password= "

Set RecordCollectio n=connectionToD atabase.Execute ("Select * from Customers") *************** *************** *************** *************** ***

*************** *************** *************** *************** ***
Set connectionToDat abase=Server.Cr eateObject("ADO DB.Connection")
connectionToDat abase.Connectio nTimeout = 60
connectionToDat abase.Open "DSN=Customer;u ser id=SA;password= "

Set RecordCollectio n=Server.Create Object("ADODB.R ecordset")
recordCollectio n.Open "Select * from Customers",conn ectionToDatabas e
*************** *************** *************** *************** ***

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.c om> 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 connectionToDat abase=Server.Cr eateObject("ADO DB.Connection")
connectionToDat abase.Connectio nTimeout = 60
connectionToDat abase.Open "DSN=Customer;u ser id=SA;password= "

Set RecordCollectio n=connectionToD atabase.Execute ("Select * from Customers")
*************** *************** *************** *************** ***

*************** *************** *************** *************** ***
Set connectionToDat abase=Server.Cr eateObject("ADO DB.Connection")
connectionToDat abase.Connectio nTimeout = 60
connectionToDat abase.Open "DSN=Customer;u ser id=SA;password= "

Set RecordCollectio n=Server.Create Object("ADODB.R ecordset")
recordCollectio n.Open "Select * from Customers",conn ectionToDatabas e
*************** *************** *************** *************** ***

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.c om> 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 connectionToDat abase=Server.Cr eateObject("ADO DB.Connection")
connectionToDat abase.Connectio nTimeout = 60
connectionToDat abase.Open "DSN=Customer;u ser id=SA;password= "

Set RecordCollectio n=connectionToD atabase.Execute ("Select * from Customers")
*************** *************** *************** *************** ***

*************** *************** *************** *************** ***
Set connectionToDat abase=Server.Cr eateObject("ADO DB.Connection")
connectionToDat abase.Connectio nTimeout = 60
connectionToDat abase.Open "DSN=Customer;u ser id=SA;password= "

Set RecordCollectio n=Server.Create Object("ADODB.R ecordset")
recordCollectio n.Open "Select * from Customers",conn ectionToDatabas e
*************** *************** *************** *************** ***

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 = adOpenForwardOn ly (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.records et")
cn.storedproced urename param1,...,parm N, 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
5338
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 records 1 : connection.execute "delete from X record 1" 2. The procedure adds record 1 again using the recordset object.
5
7408
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 record... correct? thanks
2
13618
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 * from Employee;" <% Dim objRS, sqlStmt set objRS = Server.CreateObject("ADODB.Recordset") Dim conn Set conn = Server.CreateObject("ADODB.Connection")
2
4566
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). conn.execute strSQL,,129
18
6146
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 src = "SELECT Count(*) FROM reviewer INNER JOIN pp_officer " & _ "ON reviewer.reviewer_id = pp_officer.ppo_rev_id " & _ "WHERE rev_login = 'EllisonL'" Set rL = CurrentProject.Connection.Execute(src, , adCmdText)
1
2590
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 as String 'that'll be a parameter for the secondary sub someVar = "blah"
2
9432
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 soccer clubs which he will be coaching; thus he can select only one soccer club for a new coach or multiple soccer clubs. This is how I am trying it: When this Form will be submitted, the new coaches name will be inserted in a MS-Access DB table...
0
9006
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 Recordset? Does the Recordset support Bookmarks? Can we use the Find and/or Seek Methods with this Recordset? Does the Recordset support the use of Indexes? Will the Absoluteposition property be able to be used on this Recordset? etc....
1
7202
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 procs, calling Execute() is no problem using JavaScript: var rs = cmd.Execute(); However, for non-recordset returning stored procs -- and this app has many -- I need to call Execute() passing adExecuteNoRecords for the Options parameter,...
0
9568
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9398
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10160
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9951
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8831
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5275
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2805
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.