Using Xp_sendmail In ASP?
Does anyone have a code snippet or example on using the xp_sendmail SQL procedure from an ASP page (VBscript)? I have no problem with the stored procedure from a query and I think my problem is getting the parameters passed to the procedure correctly, or just in using stored procedures from ASP.
I can execute this SQL from Query Analyzer fine:
xp_sendmail "testuser", "Hello World!"
I've tried this in ASP:
strSQL = "EXEC xp_sendmail 'testuser', 'Hello World!'"
conn.Execute strSQL
But I don't get any error, no mail gets sent and it hangs my test server. I'm using the SA account and password for the OLEDB connection. Can't tell if the server is hanging in SQL or ASP, but it locks up hard, no keyboard/mouse functions even work.
View Replies
I have a stored procedure that builds and sends an email using xp_sendmail. It is called after the user makes a change to a form (it tells the support centre that a change has occurred.)
The last bit of my SP is this:
-- It fails if it has no recipient list
if isnull(@recip, '') = '' set @recip = @supportemail
declare @rc int -- have also tried changing it to bit
exec @rc = master..xp_sendmail
@recipients = @supportemail
, @message = @msg
, @subject = @subj
, @no_output = 'False'
, @query = @q
, @width = 200
/*
Return Code Values
0 (success) or 1 (failure)
*/
select @rc
return @rc
If I call it through query analyzer, @rc is 0 and I receive the email.
If I call it through my ASP page (which worked earlier), cint(rs.fields(0)) is -1 and I do not get the email.
strSQL = "exec pr_EmailNotification " & iRequestID
writeline "<P>" & strSQL
set rs = ConnObj.Execute (strSQL)
writeline "<P> Result: " & cint(rs.fields(0)) '0 (success) or 1 (failure)
(All variables are declared.)
It was working earlier, I had proven it... I thought it was the return @rc line that was doing it and was just keeping in select @rc for debugging. When I was ready to move on, I removed my debug statement, and then it started failing. I've put it back in, but it still fails, so I must have also removed something else, or changed something, or something.
I'm at wits end. It still works perfectly through Query Analyzer. But not ASP.
View Replies
View Related