Where to put ERROR CODE

Results 1 to 2 of 2

Thread: Where to put ERROR CODE

  1. #1
    Join Date
    Dec 1969

    Default Where to put ERROR CODE

    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 anybody if you help me. Thanks<BR><BR><BR>Herez my code:<BR>&#060;%<BR>sess = Session("sessID")<BR><BR>Dim con &#039;Holds the Database Connection Object<BR>Dim rs &#039;Holds the recordset for the records in the database<BR>Dim strSQL &#039;Holds the SQL query to query the database <BR>Dim errSQL &#039;&#039;Holds the errSQL query to query the database <BR><BR>Set con = Server.CreateObject("ADODB.Connection")<BR>con.Ope n "DSN=test"<BR><BR>Set rs = Server.CreateObject("ADODB.Recordset")<BR>strSQL = "SELECT * FROM order WHERE sessID = &#039;" &sess& "&#039;"<BR><BR>rs.Open strSQL, con<BR><BR>&#039;------Check Error-----------<BR><BR>If(err.number &#060;&#062; 0) Then<BR><BR> Response.write("&#060;strong&#062;" & "Error Occured:" & err.description & "&#060;/strong&#062;")<BR> errSQL = "INSERT INTO errLog (errDate, errTime, errDesc)"<BR> errSQL = errSQL & "VALUES (&#039;" & date <BR> errSQL = errSQL & "&#039;,&#039;" & time <BR> &#039;errSQL = errSQL & "&#039;,&#039;" & err.description & "&#039;)"<BR><BR>con.Execute(errSQL)<BR><BR>ELSE<B R><BR>&#039;----------ELSE SEND E-MAIL----------------------------<BR><BR>On Error Resume Next<BR>rs.MoveFirst<BR>do while Not rs.eof<BR><BR>&#039;-----------SEND MAIL USING (BASP21)---------------***********************<BR>&#039;----P.S. (CDONTS not using on purpose)------//<BR><BR><BR><BR>email1 = rs("email1") <BR>&#039;------------------------------------------------------///<BR> Set ObjBasp = Server.CreateObject("basp21")<BR> Const m_sv = "mail.co-123"<BR> m_from = ***@***.com<BR> m_title = "Thanks"<BR> m_body = "Thanks, & rs("name1") & vbcrlf & _ <BR> "Your address is:" & rs("address")<BR> <BR> rc = ObjBasp.SendMail(m_sv,email1,m_from,m_title,m_body ,"")<BR><BR>&#039;------------END OF SENDING EMAIL-----------------**********<BR><BR>rs.MoveNext<BR>loop<BR>&#039;-------------------------------------------------------------<BR><BR>Session.Abandon<BR><BR>Response.Redirect(" thanks.asp")<BR>end if<BR><BR>con.close<BR>set con = nothing<BR><BR>%&#062;<BR>

  2. #2
    Join Date
    Dec 1969

    Default You will never get to...

    ...that error handling code. Because you don&#039;t do the ON ERROR RESUME NEXT until after the code happens!<BR><BR>You can *ONLY* handle errors WHILE you are in the "RESUME NEXT" state.<BR><BR>So move the ON ERROR RESUME NEXT to just before the rs.Open line. <BR><BR>But then, when you are no longer expecting an error, you should SHUT IT BACK OFF using ON ERROR GOTO 0. You should leave RESUME NEXT active for a short a period as possible.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts