Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

maintain database consistency in asp

Status
Not open for further replies.

Mopei

Programmer
Oct 6, 2006
1
US
Hi everyone,
I am an old user here, and I cannot login with my old userID any more. So I registered with different name.

In asp.net we can use sqltransaction object and try... catch block to enforce atomic transaction, if there is a database statement or transacton cause the error, no update is done.
What about in classic asp. how to do it.
Can you throw some ideas to me.
Thank you.
Mopei
 
There is very little you can do in the way of error catching in VBScript. You have a little more flexibility if your using Javascript for your server-side scripting.

VBScript basically has only one option, which is an On Error Resume Next. once you issue this statement you would need to check the err object continuously to see if an error has occurred yet. With ADO there is an additional step involved because the COnnection object has it's own errors collection that you would have to check.

basically you would be looking at something like:
Code:
<%
Option Explicit

'.. do stuff, do stuff

'-- start block of code you want to error catch in
'tell the system to ignore any error and continue executing
On Error Resume Next

Dim Conn, RS
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Connection string here"

'check for errors connecting
If err.Number <> 0 Then
   Response.Write "oops, there was an error"
   Response.End
ElseIf Conn.errors.Count > 0 Then
   Response.Write "oops, there was an error"
   Response.End
End If

Set RS = Conn.execute("SELECT blah FROM MyTable WHERE 1=1")

'check for errors executing
If err.Number <> 0 Then
   Response.Write "oops, there was an error"
   Response.End
ElseIf Conn.errors.Count > 0 Then
   Response.Write "oops, there was an error"
   Response.End
End If

'...etc

'turn off the resume next
On Error Goto 0

My advice would be to google for some online articles about this. There are a few fairly complex error handling functions out there to replace the continual checks I had above. While it would still be a pain to call a funciton in each place I just checked the Err object, there isn't much else available in VBScript.

Note: My syntax may be off on the Conn.errors portion. I seem to recall that the errors property is a collection, but I could be mistaken. Someone correct me if I am misremembering.

-T

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top