ASP Transaction

Hold multiple data transactions in a transaction so that if one fails the whole transaction fails.

<%
on error resume next
f1 = request("field1")
f2 = request("field2")
set con=server.createobject("ADODB.Connection")
    con.Open "MyDSN"
        con.beginTrans
        con.execute "Insert Into Table1(f1,f2) values(" & f1 & "," & f2 & ")"
        con.execute "Insert Into Table2(f1,f2) values(" & f1 & "," & f2 & ")"
if Err.Number <> 0 then
    con.RollBackTrans
    con.close
    set con = nothing
    response.write Err.Description
else
    con.CommitTrans
    con.close
    set con =nothing
    response.write "Data inserted successfully."
end if

%>



Back To Top
© 1998 - 2024 psacake.com
Version 7.21 | Advertise on this site