Begin / RollBack / Commint Transaction
Publicado por Adolfo (55 intervenciones) el 10/11/2011 17:09:35
Estoy tratando de aprender a usar el Begin / Rollback y Commit, pero el codigo que uso me presenta el error: "OleDbConnection does not support parallel transactions."
Alguien sabe que es lo que estoy haciendo mal?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If m_cn.State = ConnectionState.Closed Then
Dim VarPath As String
Dim objFile As New System.IO.StreamReader( _
System.AppDomain.CurrentDomain.BaseDirectory() & "\DireccionBD.txt", True)
VarPath = objFile.ReadToEnd()
objFile.Close()
objFile.Dispose()
m_cn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source= " & VarPath & "\BDMantenimiento.accdb;"
m_cn.Open()
End If
DTInfoFac.Clear()
m_cn.BeginTransaction()
Dim tranOleDb As OleDbTransaction
tranOleDb = m_cn.BeginTransaction '<--------- this is the line where it shows the error message.
Try
Try
m_DA = New OleDbDataAdapter("Select * From TBPersonalizar", m_cn)
m_CB = New OleDbCommandBuilder(m_DA)
m_DA.Fill(DTInfoFac)
NumFacturaAct = DTInfoFac.Rows(m_rowPosition)("NumFacturaAct").ToString()
TxtNumFactura.Text = "F-" & Format(NumFacturaAct + 1, "00000000")
NumFacturaAct += 1
If NumFacturaAct = 9999999 Then
NumFacturaAct = 0
End If
With DTInfoFac
.Rows(m_rowPosition)("NumFacturaAct") = NumFacturaAct
End With
m_DA.Update(DTInfoFac)
Catch exOleDb As OleDbException
MessageBox.Show(exOleDb.Message)
tranOleDb.Rollback()
Exit Sub
Catch ex As Exception
MessageBox.Show(ex.Message)
tranOleDb.Rollback()
Exit Sub
End Try
Finally
tranOleDb.Commit()
If m_cn.State = ConnectionState.Open Then
m_cn.Close()
End If
End Try
End Sub
Apreciaria cualquier sugerencia
Gracias.
Alguien sabe que es lo que estoy haciendo mal?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If m_cn.State = ConnectionState.Closed Then
Dim VarPath As String
Dim objFile As New System.IO.StreamReader( _
System.AppDomain.CurrentDomain.BaseDirectory() & "\DireccionBD.txt", True)
VarPath = objFile.ReadToEnd()
objFile.Close()
objFile.Dispose()
m_cn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source= " & VarPath & "\BDMantenimiento.accdb;"
m_cn.Open()
End If
DTInfoFac.Clear()
m_cn.BeginTransaction()
Dim tranOleDb As OleDbTransaction
tranOleDb = m_cn.BeginTransaction '<--------- this is the line where it shows the error message.
Try
Try
m_DA = New OleDbDataAdapter("Select * From TBPersonalizar", m_cn)
m_CB = New OleDbCommandBuilder(m_DA)
m_DA.Fill(DTInfoFac)
NumFacturaAct = DTInfoFac.Rows(m_rowPosition)("NumFacturaAct").ToString()
TxtNumFactura.Text = "F-" & Format(NumFacturaAct + 1, "00000000")
NumFacturaAct += 1
If NumFacturaAct = 9999999 Then
NumFacturaAct = 0
End If
With DTInfoFac
.Rows(m_rowPosition)("NumFacturaAct") = NumFacturaAct
End With
m_DA.Update(DTInfoFac)
Catch exOleDb As OleDbException
MessageBox.Show(exOleDb.Message)
tranOleDb.Rollback()
Exit Sub
Catch ex As Exception
MessageBox.Show(ex.Message)
tranOleDb.Rollback()
Exit Sub
End Try
Finally
tranOleDb.Commit()
If m_cn.State = ConnectionState.Open Then
m_cn.Close()
End If
End Try
End Sub
Apreciaria cualquier sugerencia
Gracias.
Valora esta pregunta


0