
30/10/2008, 19:20
|
 | | | Fecha de Ingreso: septiembre-2004 Ubicación: Chapis Data Center
Mensajes: 27
Antigüedad: 20 años, 4 meses Puntos: 0 | |
Respuesta: Problema con Transacciones mySQL en VB.NET Mi problema es que no ejecuta los querys, no marca ningun error; simplemente no hace nada. Mis Tablas en cuestion ya son InnoDB, incluso probe hacer la transaccion manualmente via consola y si funciono.
Utilizo este string de coneccion:
Código:
<add key="connStringGrabar" value="Server=miserver;Database=mibd;User id=usuario;Password=noteladigo;Pooling=false;Connection Lifetime=1; Max Pool Size=1" />
Utilizo esta funcion:
Código:
Public Function EjecutaTrans(ByVal sentencias As ArrayList) As Boolean
Dim hecho As Boolean = False
Dim myConnection As New MySqlConnection
myConnection.ConnectionString = cstrCadenaConexion
myConnection.Open()
Dim myCommand As MySqlCommand = myConnection.CreateCommand()
Dim myTrans As MySqlTransaction
' Inicia transacción local.
myTrans = myConnection.BeginTransaction()
' Must assign both transaction object and connection
' to Command object for a pending local transaction
myCommand.Connection = myConnection
myCommand.Transaction = myTrans
Try
Dim sentencia As String
For Each sentencia In sentencias
myCommand.CommandText = sentencia
myCommand.ExecuteNonQuery()
Next
myTrans.Commit()
hecho = True
Catch e As Exception
e.ToString()
Try
myTrans.Rollback()
Catch ex As MySqlException
If Not myTrans.Connection Is Nothing Then
Console.WriteLine("An exception of type " + ex.GetType().ToString() + _
" was encountered while attempting to roll back the transaction.")
End If
ex.ToString()
End Try
Console.WriteLine("An exception of type " + e.GetType().ToString() + _
"was encountered while inserting the data.")
Console.WriteLine("Neither record was written to database.")
Finally
myConnection.Close()
End Try
Return hecho
End Function
Y la utilizo desde este metodo:
Código:
Public Function Agregar() As String
Dim ent As New ConsultasGenerales
Dim dr As MySqlDataReader
Dim objABCTablasSQL As New Normay.ElArco.Source.DataBase.ABCTablasSQL
Dim transacciones As New ArrayList
Dim strSQL As String = "INSERT INTO Traspaso (id_almacen_origen,id_almacen_destino,fecha,observaciones,id_empleado,entrego,costo) VALUES (" & _
Me.intId_almacenorigen & "," & Me.intId_almacendestino & ",'" & Me.strFecha & "','" & _
Me.strObservacionesGenerales & "','" & Me.strId_empleado & "','" & Me.strEntrego & "'," & Me.sngcosto & ");"
Try
transacciones.Add(strSQL)
strSQL = ""
Dim i As Integer
strSQL = "INSERT INTO TraspasoProducto (id_traspaso,id_producto,cantidad,costo) VALUES "
For i = 1 To colid_Productos.Count
If i < colid_Productos.Count Then
strSQL = [String].Concat(strSQL, "((SELECT MAX(id_traspaso) FROM Traspaso),'" & colid_Productos(i) & "'," & Me.colCantidades(i) & "," & Me.colcosto(i) & "),")
Else
strSQL = [String].Concat(strSQL, "((SELECT MAX(id_traspaso) FROM Traspaso),'" & colid_Productos(i) & "'," & Me.colCantidades(i) & "," & Me.colcosto(i) & ");")
End If
transacciones.Add(Actualiza(Me.intId_almacenorigen, Me.colCantidades(i), Me.colid_Productos(i), False))
transacciones.Add(Actualiza(Me.intId_almacendestino, Me.colCantidades(i), Me.colid_Productos(i), True))
Next
Try
transacciones.Add(strSQL)
objABCTablasSQL.EjecutaTrans(transacciones)
Catch ex As Exception
End Try
Agregar = "¡El Traspaso fue registrado exitosamente!"
Catch sqlExc As Exception
Agregar = "¡Ocurrió un error al registrar el Traspaso! " & sqlExc.ToString
End Try
End Function
|