classic ASP Error Handling in Data-Access

Hi Guys
I am using vbscript/AsP/MSSQL 2005 on my website
Below is a simple dababase-access subroutine in an asp web-page.
I would really appreciate if  someone could add basic error handling to it.
Thank you
Dory

SUB Order_delete
Dim sqlstr
cust_no=session("cust_no")
set Objconn = Server.CreateObject("ADODB.Connection")
Objconn.open application("Mydb)
Set rs = Server.CreateObject("ADODB.Recordset")
set rs.activeconnection=objconn
sqlstr= "DELETE FROM  ord_save"
sqlstr=sqlstr & " WHERE ord_save.cust_no like '" & cust_no & "' "
rs.open sqlstr
set rs = nothing
objconn.close
set objconn=nothing
End Sub
dory550Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Carl TawnSystems and Integration DeveloperCommented:
Basic ASP error handling uses the On Error Resume construct, something like:
SUB Order_delete

   Dim sqlstr
   cust_no=session("cust_no")

   On Error Resume Next

   set Objconn = Server.CreateObject("ADODB.Connection")
   Objconn.open application("Mydb)

   '// Check if there was an error opening the connection
   If Err.number <> 0 Then
      '// Do something with the error
   End

   Set rs = Server.CreateObject("ADODB.Recordset")
   set rs.activeconnection=objconn
   sqlstr= "DELETE FROM  ord_save"
   sqlstr=sqlstr & " WHERE ord_save.cust_no like '" & cust_no & "' "
   rs.open sqlstr

   '// Check if there was an error executing the query
   If Err.number <> 0 Then
      '// Do something with the error
   End If

   On Error Goto 0

   set rs = nothing
   objconn.close
   set objconn=nothing

End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sybeCommented:
> sqlstr= "DELETE FROM  ord_save"
> sqlstr=sqlstr & " WHERE ord_save.cust_no like '" & cust_no & "' "

Why "LIKE" and not "=" ?

And why use a recordset when you don't need one?

<%
objconn.execute sSQL, , 128
%>
is all you need to execute a statement and skip the recordset object.
0
dory550Author Commented:

Hi
Many thanks to Sybe for comments about improving my script
With reference to error-handling. I understand that basically i need first to identify the error and then  display a friendly message to the user.
I was wondering if someone could comment on that. And maybe provide some sample of a friendly messages.
thanks
Dory

0
sybeCommented:
Users are not very interested in what went wrong, but you should be. Users want to know that it gets fixed, and you want to know exactly what went wrong so you can fix it.

So the best thing is to log the exact error message to a place where you have access to, and tell the user that some error has occurred, that it has been logged, and that it will be fixed.
0
dory550Author Commented:
Hi Guys
Thank you for your help
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.