Salve a tutti, non riesco a capire perchè ricevo questo errore:
This SqlTransaction has completed; it is no longer usable.
quando cerco di chiudere una transazione. Ho controllato 100 volte il codice, e non mi sembra ci sia niente di sbagliato (un'altra chiamata precedente, variabili sballate).
P.S. chiamo i metodi BeginaTrans, Commit e/o Rollback tramite 3 funzioni diverse di una classe da me creata.
Questo il codice per le 3 operazioni più l'esecuzione della query.
Ci sto impazzendo da qualche giorno, spero possiate aiutarmi.codice:Public sub BeginTransaction() Me.Conn = New SqlConnection(Me.sConnStr) Me.Conn.Open() 'Start a local transaction Me.myTransaction = Conn.BeginTransaction() Me.mySqlCommand = new SqlCommand() Me.mySqlCommand.Connection = Me.Conn Me.mySqlCommand.Transaction = Me.myTransaction end sub Public sub CommitTransaction() Me.myTransaction.Commit() Me.Conn.Close() end sub Public function RollbackTransaction() Me.myTransaction.Rollback() Me.Conn.Close() end function Public function ExecuteNonQuery(ByVal SQL As String, optional sqlParameters as ArrayList = nothing, optional toClose as boolean = true) as object Dim objReturn as object = nothing if Me.Conn is nothing then Me.Conn = New SqlConnection(Me.sConnStr) Me.Conn.Open() else if Me.Conn.State <> ConnectionState.Open then Me.Conn.Open() end if if Me.mySqlCommand is nothing then Me.mySqlCommand = new SqlCommand(SQL, Me.Conn) else Me.mySqlCommand.CommandText = SQL end if Try if not sqlParameters is nothing then Me.mySqlCommand.CommandType = CommandType.StoredProcedure Dim sqlPar as SqlParameter for each sqlPar in sqlParameters Me.mySqlCommand.Parameters.Add(sqlPar) next else Me.mySqlCommand.CommandType = CommandType.Text end if Me.mySqlCommand.ExecuteNonQuery() Catch e As Exception objReturn = e End Try 'must be clean up? if toClose then Me.Conn.Close() Me.mySqlCommand.Dispose() Me.Conn.Dispose() end if return objReturn End function


Rispondi quotando