vipinkrshamra
Programmer
Hi ,
I am trying to use use dataadapter.update with in trascantion. But it is failing with following exception. "System.InvalidOperationException: Execute requires the command to have a transaction object when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized."
If I remove trasaction from my code everything works fine but once I use trascation same code fails.
Below code fail at "da.Update(ds, TableName)" if transactions are used.
***********
Private Function Save(ByVal da As SqlDataAdapter, ByVal ds As DataSet, ByVal TableName As String) As Boolean
SaveMainTable = False
Dim intSuccessfulInsertion As Integer
Dim myTrans As SqlTransaction
Try
Dim bldr1 As SqlCommandBuilder = New SqlCommandBuilder(da)
da.InsertCommand = bldr1.GetInsertCommand
da.InsertCommand.Connection.Open()
myTrans = da.InsertCommand.Connection.BeginTransaction
intSuccessfulInsertion = da.Update(ds, TableName) -->Failing here
myTrans.Commit()
SaveMainTable = True
Catch sqlex As SqlException
myTrans.Rollback()
Catch ex As Exception
WriteLogFile("Problem in updating database." & ex.ToString, "ProcessHTML")
End Try
End Function
I am trying to use use dataadapter.update with in trascantion. But it is failing with following exception. "System.InvalidOperationException: Execute requires the command to have a transaction object when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized."
If I remove trasaction from my code everything works fine but once I use trascation same code fails.
Below code fail at "da.Update(ds, TableName)" if transactions are used.
***********
Private Function Save(ByVal da As SqlDataAdapter, ByVal ds As DataSet, ByVal TableName As String) As Boolean
SaveMainTable = False
Dim intSuccessfulInsertion As Integer
Dim myTrans As SqlTransaction
Try
Dim bldr1 As SqlCommandBuilder = New SqlCommandBuilder(da)
da.InsertCommand = bldr1.GetInsertCommand
da.InsertCommand.Connection.Open()
myTrans = da.InsertCommand.Connection.BeginTransaction
intSuccessfulInsertion = da.Update(ds, TableName) -->Failing here
myTrans.Commit()
SaveMainTable = True
Catch sqlex As SqlException
myTrans.Rollback()
Catch ex As Exception
WriteLogFile("Problem in updating database." & ex.ToString, "ProcessHTML")
End Try
End Function