I'm trying to modify a long long code within a button click by make the insert/update/delete/select using the same transaction. Purpose is to make sure every operation can be rollback instead of some table inserted but some not. But I get this error:
The SqlCommand is currently busy Open, Fetching.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidO perationExcepti on: The SqlCommand is currently busy Open, Fetching.
Source Error:
Line 794: SqlTrans.Commit ()
Line 795: Else
Line 796: SqlTrans.Rollba ck()
Line 797: End If
Line 798: MyConnection.Cl ose()
Source File: D:\Intranet\EFo rmApplication\p review\PMRF.asp x Line: 796
Stack Trace:
[InvalidOperatio nException: The SqlCommand is currently busy Open, Fetching.]
System.Data.Sql Client.SqlComma nd.set_Transact ion(SqlTransact ion value) +57
System.Data.Sql Client.SqlTrans action.GetServe rTransactionLev el() +59
System.Data.Sql Client.SqlTrans action.CheckTra nsactionLevelAn dZombie() +63
System.Data.Sql Client.SqlTrans action.Rollback () +73
ASP.PMRF_aspx.b tnApprove_Click (Object sender, EventArgs e) in D:\Intranet\EFo rmApplication\p review\PMRF.asp x:796
System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +108
System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring eventArgument) +57
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler sourceControl, String eventArgument) +18
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +33
System.Web.UI.P age.ProcessRequ estMain() +1292
Part of the code as below:
Am I using the correct way in code above? Is there any suggestion on how to modify the existing code using the same transaction? Maybe I do not so understand on how to using the transaction code... Appreciating for any suggestion and help given.... :-)
The SqlCommand is currently busy Open, Fetching.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidO perationExcepti on: The SqlCommand is currently busy Open, Fetching.
Source Error:
Line 794: SqlTrans.Commit ()
Line 795: Else
Line 796: SqlTrans.Rollba ck()
Line 797: End If
Line 798: MyConnection.Cl ose()
Source File: D:\Intranet\EFo rmApplication\p review\PMRF.asp x Line: 796
Stack Trace:
[InvalidOperatio nException: The SqlCommand is currently busy Open, Fetching.]
System.Data.Sql Client.SqlComma nd.set_Transact ion(SqlTransact ion value) +57
System.Data.Sql Client.SqlTrans action.GetServe rTransactionLev el() +59
System.Data.Sql Client.SqlTrans action.CheckTra nsactionLevelAn dZombie() +63
System.Data.Sql Client.SqlTrans action.Rollback () +73
ASP.PMRF_aspx.b tnApprove_Click (Object sender, EventArgs e) in D:\Intranet\EFo rmApplication\p review\PMRF.asp x:796
System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +108
System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring eventArgument) +57
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler sourceControl, String eventArgument) +18
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +33
System.Web.UI.P age.ProcessRequ estMain() +1292
Part of the code as below:
Code:
try
Cmd6.Transaction = SqlTrans
objDRReq = Cmd6.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
If objDRReq.Read() Then
fReqFormID = objDRReq("ReqForm_ID")
fRequestorID = objDRReq("Requestor_ID")
fReqName = objDRReq("ReqName")
fEFormID = objDRReq("EForm_ID")
fEFormName = objDRReq("EForm_Name")
fReqDate = objDRReq("ReqDate")
fReqTime = objDRReq("ReqTime")
fJustification = objDRReq("Justification")
End If
objDRReq.Close()
catch
BooTrans = true
end try
...
...
...
try
Cmd8.Transaction = SqlTrans
objDRCount = Cmd8.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
If objDRCount.Read() Then
CountNum = objDRCount("Num") ' Count the total number of response (approve or reject) form the approver '
End If
objDRCount.Close()
catch
BooTrans = true
end try
...
...
...
If BooTrans = false Then
SqlTrans.Commit()
Else
SqlTrans.Rollback()
End If
MyConnection.Close()
Comment