Good Day Folks, I'm trying to perform a database transaction with asp.net. In the old days of asp the following code worked. on error resume next theDB.BeginTrans ' Perform insert, update, or delete if Err.Number=0 then theDB.CommitTrans else theDB.RollBackTrans
end if theDB.close set theDB=Nothing How would I accomplish the same thing with asp.net ? Thanks in advance
For those who are interested here is the final code which executed correctly. ------------------------------ Transaction Code <script Language=VB Runat=Server> Sub Page_Load(Sender As Object, e As EventArgs) dim rcDB as OracleConnection dim theSQL as string,connstring
as string const oracleDSN="WEB" const p_userid="x11111" const p_password="teacher" const p_userid2=" 13923" const p_gradecode="05" const p_newgradecode="07" connstring="Data Source=" & oracleDSN & ";User ID=" & p_userid & ";Password=" & p_password & ";Enlist=False"
theSQL="UPDATE WEB_TCHR_COMMENT" & _ " set grade_code='" & p_newgradecode & "'" & _ " WHERE grade_code='" & p_gradecode & "'" & _ " AND employee_id='" & p_userid2 & "'" rcDB =New OracleConnection(connstring) rcDB.open() Dim myCommand As New OracleCommand(theSQL
, rcDB) dim rcDBTrans as OracleTransaction=rcDB.BeginTransaction() Try myCommand.ExecuteNonQuery() rcDBTrans.Commit() Response.write("Success - Transaction commited") Catch e1 as Exception rcDBTrans.Rollback() Response.write("Error - Transaction cancelled")
Response.write(e1.message & "
") Response.write(e1.source & "
") Finally End Try myCommand.dispose rcDB.close rcDB.dispose End Sub </script> Done !
c28560
Member
80 Points
17 Posts
How to do transactions ?
Sep 24, 2003 03:07 PM|LINK
cpuDemon
Member
60 Points
12 Posts
Re: How to do transactions ?
Sep 24, 2003 04:54 PM|LINK
string strSQL = "Update TBL SET Field = 'a' WHERE key = 'val"; objConn = new OracleConnection(ConfigurationSettings.AppSettings["CnxStr"]); objCmd = new OracleCommand(strSQL, objConn); objCmd.Connection.Open(); objTrans = objConn.BeginTransaction(); objCmd.Transaction = objTrans; try { objCmd.Parameters.Clear(); objCmd.ExecuteNonQuery(); objTrans.Commit(); }catch( Exception ex) { objTrans.Rollback(); lblError.Text = "Error Processing Rrquest"; Trace.Write("Query Catch", "Failure"); Trace.Write("Ex Message", ex.Message); Trace.Write("Ex Stack", ex.StackTrace.ToString()); Trace.Write("Ex Info", ex.GetType().MemberType.ToString()); Trace.Write("Ex Type", ex.GetType().Name.ToString()); }finally { objCmd.Connection.Close(); objConn.Close(); objConn.Dispose(); objConn = null; }msc28560
Member
80 Points
17 Posts
Re: How to do transactions ?
Sep 24, 2003 07:41 PM|LINK
") Response.write(e1.source & "
") Finally End Try myCommand.dispose rcDB.close rcDB.dispose End Sub </script> Done !