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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need example of update query and rollback

Status
Not open for further replies.

thelordoftherings

Programmer
May 16, 2004
616
0
0
IL
Hello,

Let's say I've opened this connection to the Database:

openstr ="myTest"
Set connection = Server.CreateObject("ADODB.connection")
connection.Open openstr, "", ""
Set rs = Server.CreateObject("ADODB.Recordset")

Can someone please show me a simple code example of update query and rollback handling in case the update fails?
 
i don't use recordset objects for updates...less overhead...

Code:
openstr ="myTest"
Set connection = Server.CreateObject("ADODB.connection")
connection.Open openstr, "", ""
sql = "UPDATE foo SET bar = 'bar' WHERE id = 1"

rem turn on error trapping
on error resume next

rem begin a transaction
connection.beginTrans

rem attempt update
connection.execute(sql)

rem see if it worked
if (err.number <> 0) then
  rem failed, rollback
  connection.rollbackTrans
  err.clear
else 
  rem succeeded, commit
  connection.commitTrans
end if

rem turn off error trapping
on error goto 0

=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
 
as far as i know...it should just implement the underlying database's transaction facilities


=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
 
Does the connection.rollbackTrans returns the updated row to it's original state?
 
that's what transactions do...how about writing a test & try it ;-)


=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
 
That's what I figured but how does it actually do it? Does it save the old record before changing it? Does this rollback affective in Access DB as well?
 
it's up to the database you're using. using Connection.beginTrans is only an interface to your database's transaction method. if your database does not support transactions, Connection.beginTrans will fail and/or throw an error.


=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
 
i don't know...try the access forum or google


=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top