navigation
a webmaster learning community
     Home    Register     Search      Help      Login    
Sponsors

Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions.

Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.

Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax

Search Forums
 

Advanced search
Recent Posts

 Todays Posts
 Most Active posts
 Posts since last visit
 My Recent Posts
 Mark posts read

Microsoft MVP

 

Invoking a Stored Procedure via ASP

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Web Development >> ASP and Database >> Invoking a Stored Procedure via ASP
Page: [1]
 
bowker

 

Posts: 34
Joined: 6/30/2003
Status: offline

 
Invoking a Stored Procedure via ASP - 7/7/2003 16:25:38   
I have a stored procedure that accepts an email address as a parameter (see below) and then sends an email to the address that was entered in the form. I' d like to invoke this stored procedure from an ASP page where I have a form that has the " email" field filled out. Upon submitting the form, I' d like the stored procedure to run using the contents from the form.

Ultimately I want to have a list of checkboxes (or a drop down with multi-select) in a form that when selected, have the corresponding values for employee email addresses. That way when the form is submitted, it will send the stored procedure all of the parameters (email addresses chosen in the form) and then issue emails to all of the people who were selected. I know I will need to change my stored procedure to accomplish this, but right now I just want to know how I can invoke the procedure via ASP in Frontpage using MS-SQL 2000 as the data store.

********STORED PROCEDURE********

CREATE PROC sp_bowker_email @email VARCHAR (50) AS

DECLARE @_subject varchar (50)
DECLARE @_query varchar (50)
DECLARE @_message varchar (200)
Declare @_mailadd varchar (50)

SET @_subject = ' Your email is ' + @email
SET @_message = ' This is a test for address ' + @email
--Set @_mailadd = ' select emailaddress from atestemail where atestmail.emailcode = aproject.status'

EXEC master.dbo.xp_startmail
EXEC master.dbo.xp_sendmail
@recipients = @email,
@subject = @_subject,
@message = @_message,
@query = @_query,
@dbuse = ' workrequests' ,
@width = 160,
@attach_results = False
exec master.dbo.xp_stopmail
GO

***************

Thank you in advance.
alveyuk

 

Posts: 80
Joined: 4/4/2002
From: Lincs United Kingdom
Status: offline

 
RE: Invoking a Stored Procedure via ASP - 7/7/2003 19:10:36   
I have done a similar thing with an Informix database where I had an insert trigger invoking the stored procedure. The insert trigger was on a table I created to hold the details from the FrontPage form (name and email address etc) and the insert trigger passed these details into the stored procedure.

I have had a look at the MS-SQL help files and it should be possible to do the same type of thing. The most relevant portion of the help file seems to be under keyword of ' Trigger object'

Once the trigger is in place all that is required from the FrontPage is to insert the details collected by the form into this table.

_____________________________

Ken Alvey

(in reply to bowker)
Spooky

 

Posts: 26599
Joined: 11/11/1998
From: Middle Earth
Status: offline

 
RE: Invoking a Stored Procedure via ASP - 7/7/2003 19:13:53   
To do that with the DRW, youll need to do the Spooky diet.
The reason is, you cant validate a custom query with a SP via the wizard.

Then, when it is customised (with a basic database query similar to what you need) change the red code from :

fp_sQry=" select * from table"

to :
fp_sQry=" sp_bowker_email ' " &Request.Form(" Email" )&" ' "

Im not sure if it will work without returning records though.

_____________________________

If you arent part of the solution, then there is good money to be made prolonging the problem

§þ:)


(in reply to bowker)
Doug G

 

Posts: 1189
Joined: 12/29/2001
From: SoCal
Status: offline

 
RE: Invoking a Stored Procedure via ASP - 7/7/2003 20:04:12   
Or you can use straight asp to execute the sp. Assuming an ado connection con:

con.execute " EXEC sp_browser_email @subject=" & varSubj & " , @query=" & varQuery & " , @message=" & varMsg & " , @mailadd=" & varAddy" , , adExecuteNoRecords

This is assuming your sp variables are in the appropriate asp variables. This is a theoretical example not for cut & paste.

Check your syntax for your sp too, I don' t think it' s correct but I don' t do that many sp' s. I think all the variable declarations need to be above the AS

< Message edited by Doug G -- 7/7/2003 8:05:51 PM >


_____________________________

======
Doug G
======

(in reply to bowker)
bowker

 

Posts: 34
Joined: 6/30/2003
Status: offline

 
RE: Invoking a Stored Procedure via ASP - 7/7/2003 22:56:34   
Thanks to everyone' s replies, I believe I am one step closer.....bear with me as I am still a beginner and am not the sharpest tool in the shed either.

Here is what I came up with:

<%
Dim objConn
Set objConn = Server.CreateObject(" ADODB.Connection" )
objConn.Open (" myconnectionstring" )
objConn.Execute " EXEC sp_bowker_email_novar"
objconn.Close
Set objconn = Nothing
%>

This worked perfectly (with " myconnectionstring" replaced with the appropriate info). I even amended the execute statement to include a single parameter and, after changing my SP slightly, was able to send an email address as a parameter and have it send correctly. Aside from the fact that it worked, am I way off base here? Did I break some golden rule? Is there a better way?

Now, I' d like to take a form from one page and have it' s " entries" be the parameters that the SP is looking for (not necessarily an email based SP). I looked at Spooky' s reply, but since I am not using the DRW anywhere on this page I wasn' t sure how to add it and make it all fly or even why.

I am thinking that it would be cool if I could simply make the line

objConn.Execute " EXEC sp_bowker_email_novar"

read

objConn.Execute " EXEC sp_bowker_email_novar <%=formvariable%>"

But I know that won' t work. Do you get what I am after though?

Again, thanks in advance. And thanks to all of you for putting up with us newbies who don' t always get it. I love this site.....

(in reply to bowker)
Spooky

 

Posts: 26599
Joined: 11/11/1998
From: Middle Earth
Status: offline

 
RE: Invoking a Stored Procedure via ASP - 7/8/2003 1:39:19   
Yes, you are heading in the right direction :)
I made the assumption before you were trying to use the DRW [:' (]

You should be able to pass parameters in the string :

objConn.Execute " EXEC sp_bowker_email_novar " &request.form(" email" )&" "

Depending how the sp is setup, you may need to surround the variables in quotes.

You mention above that you got it going with a parameter? but I dont see that script.

_____________________________

If you arent part of the solution, then there is good money to be made prolonging the problem

§þ:)


(in reply to bowker)
bowker

 

Posts: 34
Joined: 6/30/2003
Status: offline

 
RE: Invoking a Stored Procedure via ASP - 7/8/2003 1:47:18   
Here is the objconn line for the other SP that took a parameter...

objConn.Execute " exec sp_bowker_email ' someone@coolsite.com, someonelse@coolsite.com, spookyrocks@coolsite.com' "

This allowed the SP to send mutliple emails...

Going to go try your syntax..but first I' ve got to finish up CSI! :)

(in reply to Spooky)
Spooky

 

Posts: 26599
Joined: 11/11/1998
From: Middle Earth
Status: offline

 
RE: Invoking a Stored Procedure via ASP - 7/8/2003 2:05:00   
Then youll need to include quotes like so :
objConn.Execute " exec sp_bowker_email ' " & Request.Form(" Email" ) &" ' "  


Back to TV! :)

_____________________________

If you arent part of the solution, then there is good money to be made prolonging the problem

§þ:)


(in reply to bowker)
bowker

 

Posts: 34
Joined: 6/30/2003
Status: offline

 
RE: Invoking a Stored Procedure via ASP - 7/8/2003 3:08:31   
That worked beautifully! Thank you! Now, to raise the bar a bit, or at least to clarify it some for me, how would that objconn line look if I had three parameters to send from the form--assuming that the SP was setup appropriately.

Would this work?

objConn.Execute " exec sp_bowker_email ' " & Request.Form(" Email" ) & Request.Form(" vartwo" ) & Request.Form(" varthree" ) &" ' "

Thank you again,

-Voting Spooky for President

(in reply to Spooky)
Spooky

 

Posts: 26599
Joined: 11/11/1998
From: Middle Earth
Status: offline

 
RE: Invoking a Stored Procedure via ASP - 7/8/2003 22:56:01   
Yes, but each variable would need to be seperated by a comma, and if required in the SP, quotes as well.

_____________________________

If you arent part of the solution, then there is good money to be made prolonging the problem

§þ:)


(in reply to bowker)
Page:   [1]

All Forums >> Web Development >> ASP and Database >> Invoking a Stored Procedure via ASP
Page: [1]
Jump to: 1





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts