Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 28th, 2004, 06:28 PM
Registered User
 
Join Date: Jun 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default trigger stored procedures from asp

Hello

I have searched the forums but havent really seen answer to mu question.
I am trying to trigger a stored procedure from an asp site. The stored procedure gets 2 variable (supposedly from the asp site) then it updates a field in a selected table. Could anyone help me out with a link or a sniplet please? thanx
 
Old June 28th, 2004, 08:32 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

You can define your connection and recordset objects and trigger the procedure as shown below.

Code:
set Conn = Server.CreateObject("ADODB.CONNECTION")
Conn.Open "Your Connection string" 
' For connection strings you can check Connection Strings

strSql = "Execute YourProcedure @StringParam1='" & StringParam1Value & "', @intParam2=" & intParam2Value

Conn.Execute(strSql)
In case you are returning a result from your Procedure, you can use the above red code as

Code:
Set Rs = Conn.Execute(strSql)
strResult=Rs("Result_That_You_Return_From_Proc")
Response.write strResult
Hope that helps.
Cheers!

_________________________
-Vijay G
Strive for Perfection
 
Old June 29th, 2004, 03:50 PM
Registered User
 
Join Date: Jun 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Excelent. Thanx!

However...
I cant make it work.
I am using 3 parameters instead of 2. I use "centeralized" (lol) conn string which works fine for the rest of the asp pages.(those pages are successfully accessing/editing a table in the DB), but the stored proc triggering just dont work.
my sql str is something like this:

sql = "Execute docalc @num1='"&number1&"',@num2="&number2&"',@num3='"&nu mber3&"'"

Right after that I have an error report script.

I am getting " Unclosed quotation mark before the character string ',@num3=''."
or num3 is excepted by the procedure but havent ben included,
or just a syntax error.
I know its my bad putting the quotation marks to the wrong place, but so far I couldnt figure it out the correct way.


 
Old June 29th, 2004, 09:12 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

You are missing a single quote after @num2=

That's what's throwing it off.

Brian
 
Old June 29th, 2004, 09:18 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

If you are passing numeric type(Int, Float, etc...) parameters, then you don't really have to use SINGLE QUOTEs around the variables. That can be used only when you pass on STRING type(VARCHAR, nVARCHAR, etc...) values.

Cheers!

_________________________
- Vijay G
Strive for Perfection
 
Old June 30th, 2004, 12:58 AM
Registered User
 
Join Date: Jun 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanx for helping guys. Finally I got it to work this way:

set rsl = Server.CreateObject("ADODB.Recordset")
sql = "Execute docalc @num1='"& number1 &"', @num2='"& number2 &"', @num3='"& number3 &"'"
set rsl=conn.execute(sql)

 
Old July 6th, 2004, 01:47 AM
Authorized User
 
Join Date: May 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is good but u must use Command object for stored proc instead connection object coz command object is the best suit for storeproc

 
Old July 15th, 2004, 10:47 PM
Registered User
 
Join Date: Jun 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

cool thanx, but what do you mean I should/must use command object? Could you explain it please?






Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET Stored Procedures kwilliams ASP.NET 2.0 Basics 1 March 16th, 2006 11:56 PM
Stored Procedures jazzcatone Classic ASP Databases 0 August 28th, 2005 02:57 PM
asp and ms sql stored procedures solomon_13000 Classic ASP Basics 1 July 11th, 2005 12:04 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.