Print Page | Close Window

Different ways of calling SP’s

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=302
Printed Date: 28 March 2026 at 10:22pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Different ways of calling SP’s
Posted By: Vintious
Subject: Different ways of calling SP’s
Date Posted: 18 February 2003 at 8:22pm

I don't know if this should go in the database forum, but here goes.

I have an SQL 2000 database running. I am using ASP scripts to grab, update, insert, delete, etc... information from the database.

Now, I have seen two different ways of calling the stored proceedures from a database.

Let's assume that I have a database connection called "Connection" and I have declared a variable called "rst" (for my recordset).

Set rst = Connection.Execute("EXECUTE sp_name")

OR

Set rst = Server.CreateObject("ADODB.RecordSet")
rst.open "EXECUTE sp_name",Connection,3,3

Now, it would appear to me that the first way is better. First of all, you save yourself a line, and I found out I can also run another SELECT query using the same variable without having to close and Re-Set the recordset variable.

So, which way is:

  • Faster
  • Least resource intensive
  • Is the best choice??

If I'm missing something (like the way I like is really slow or something) please tell me. I'm building a large database application that I'm sure a lot of people are going to be using. I want as many optimizations as possible.

Thanks,
Vintious




Replies:
Posted By: MorningZ
Date Posted: 19 February 2003 at 8:27am
You're missing something...

the first method doesn't allow you to do any kinda of "client" recordset stuff.. such as:
- Grabbing the # of records returned
- Paging
- stuff like that

Best way to show the differences is with examples, so i'll take a few minutes to do so....

For this example, let's say i have a table called "Account" that had Three columns, UserID (primary key), Username (varchar), and Password (varchar)

So if i simply wanted to insert a new record, i might have the following set up
SPROC "sp_INSER_NEW":
CREATE PROCEDURE [dbo].[sg_INSERT_NEW]
    @uname varchar(50), @pass varchar(50)
AS
INSERT INTO Account (Username, Password) VALUES (@uname,@pass)
GO


now in ASP, i could simply use:
strSQL = "sp_INSERT_NEW '" & entered uname & "', '" & entered pass & "'"
Connection.execute(strSQL)


didn't even have to make any reference to a recordset (and the above would go for updates to)

Say i wanted a list of all accounts, simply saying:
Set rst = Connection.Execute(PROC that gets full list)

would indeed work and i would have a recordset populated with all accounts... BUT if you wanted to know how many records were pulled back (using the rst.RecordCount method), if you don't create the Recordset object explicitly, you will get "-1" everytime for that

As for speed and time of execution, there will be differences, but nothing that you'd really "see".. it's all a matter of how much information you need from the recordset

-------------
Contribute to the working anarchy we fondly call the Internet



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net