Transaction fails

Results 1 to 2 of 2

Thread: Transaction fails

  1. #1
    Join Date
    Dec 1969

    Default Transaction fails

    I am trying to insert a record into a table.<BR>If it fails (possibly due to duplicate entries), I want the transaction to rollback .<BR><BR>This is what the code looks like<BR><BR>set DBConn = server.createobject("ADODB.Connection")<BR>DBConn. open DBName, DBUser, DBPass<BR><BR>DBConn.BeginTrans<BR>set aTempRec = server.createobject("ADODB.Recordset")<BR>set aTempRec = DBConn.execute(sSQL)<BR>If DBConn.Errors.Count = 0 Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;DBConn.CommitTrans <BR>&nbsp;&nbsp;&nbsp;&nbsp;Response.Write "It Worked!"<BR>Else<BR>&nbsp;&nbsp;&nbsp;&nbsp;Respon se.Write "It Failed!"<BR>&nbsp;&nbsp;&nbsp;&nbsp;DBConn.Rollbac ktrans<BR>End If<BR>DBConn.Close<BR>Set DBConn = Nothing<BR><BR><BR><BR>When I run this, I get a Unique Constraint Violated message from IE. How come? I thought the transaction was supposed to catch all errors?<BR><BR>thanks

  2. #2
    Join Date
    Dec 1969
    Los Angeles, CA

    Default use on error resume next

    before you execute your SQL<BR><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