Click to See Complete Forum and Search --> : WHERE to put ERROR Code


yasuru
04-02-2004, 09:23 PM
I need to send mail to the user who filled up the form, but only after the data get inserted in database. For that I am inserting sessionID with other data and then on the next page calling the data using the same SessionID and sending the mail to the user. Here I want to catch error if occured. Program is working fine, but I dont know whether I put the error code in the right place or not. I shall be thankful to you if you help me with this. Thanks


Herez my code:
<%
sess = Session("sessID")

Dim con 'Holds the Database Connection Object
Dim rs 'Holds the recordset for the records in the database
Dim strSQL 'Holds the SQL query to query the database
Dim errSQL ''Holds the errSQL query to query the database

Set con = Server.CreateObject("ADODB.Connection")
con.Open "DSN=test"

Set rs = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT * FROM order WHERE sessID = '" &sess& "'"

rs.Open strSQL, con

'------Check Error-----------

If(err.number <> 0) Then

Response.write("<strong>" & "Error Occured:" & err.description & "</strong>")
errSQL = "INSERT INTO errLog (errDate, errTime, errDesc)"
errSQL = errSQL & "VALUES ('" & date
errSQL = errSQL & "','" & time
'errSQL = errSQL & "','" & err.description & "')"

con.Execute(errSQL)

ELSE

'----------ELSE SEND E-MAIL----------------------------

On Error Resume Next
rs.MoveFirst
do while Not rs.eof

'-----------SEND MAIL USING (BASP21)---------------***********************
'----P.S. (CDONTS not using on purpose)------//



email1 = rs("email1")
'------------------------------------------------------///
Set ObjBasp = Server.CreateObject("basp21")
Const m_sv = "mail.co-123"
m_from = ***@***.com
m_title = "Thanks"
m_body = "Thanks, & rs("name1") & vbcrlf & _
"Your address is:" & rs("address")

rc = ObjBasp.SendMail(m_sv,email1,m_from,m_title,m_body,"")

'------------END OF SENDING EMAIL-----------------**********

rs.MoveNext
loop
'-------------------------------------------------------------

Session.Abandon

Response.Redirect("thanks.asp")
end if

con.close
set con = nothing

%>

buntine
04-02-2004, 10:29 PM
All this code can be on the same page. Just insert the details into the database before the email is sent.. Its not just goind to skip a part of your srcipt..

Regards.

yasuru
04-02-2004, 11:13 PM
Thanks for reply,

Well, I know we insert data in DB and send mail at one go, but, instead of sending mail directly, I want to insert data in database at first step, then send mail in the second step calling the records from database. Hope I did calrify my point.

Thanks

buntine
04-03-2004, 11:36 PM
You havent specified what err is.. You need to create an ASPError object.

Also, you are only sending the email if no error occurs.. Shouldnt you be sending queryString variables to determine if an email has already been sent?

Regards.