Transaction Saves Before Commit


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 1 of 1

Thread: Transaction Saves Before Commit

  1. #1
    Join Date
    Jul 2004
    Posts
    365

    Question Transaction Saves Before Commit

    What would cause a transaction to save before the commit statement?

    I'm doing the following, I have a subroutine in a class called clsConnection, the sub looks like this;
    Code:
    Public Sub OpenTransactionConnection()
    
    If g_cnnRO.State = ConnectionState.Closed Then
    
    'SETUP THE TRANSACTION
    g_cnnRO = OpenMySqlConnection()
    g_cmdUpdateAll.Connection = g_cnnRO
    g_cmdUpdateAll.Transaction = g_Transaction
    g_cmdUpdateAll = g_cnnRO.CreateCommand()
    g_cmdUpdateAll.CommandType = CommandType.Text
    
    'START THE TRANSACTION
    g_Transaction = g_cnnRO.BeginTransaction(IsolationLevel.ReadCommitted)
    
    End If
    
    End Sub
    I call this at the beginning of the update/add. I'm executing the sql statement for the update/add like so; ( the cnnTransaction is being set the to g_cnnRO which is the transaction connection object)
    Code:
    Protected Function ExecuteNonQuery(ByVal NonSelectQuery As String, ByVal cnnTransaction As MySqlConnection) As Integer
                '   protected scope to make available only to child classes
    
                ExecuteNonQuery = 0
                mstrErrorMessage = ""
    
                Dim myMySQLCommand As MySqlCommand = cnnTransaction.CreateCommand
                myMySQLCommand.CommandText = NonSelectQuery
                myMySQLCommand.CommandType = CommandType.Text
    
                Try
                    ExecuteNonQuery = myMySQLCommand.ExecuteNonQuery()
                Catch ex As Exception
                    mstrErrorMessage = ex.Message
                Finally
                    myMySQLCommand.Dispose()
                    myMySQLCommand = Nothing
                End Try
               
    End Function
    I've also tried:
    Code:
    Protected Function ExecuteNonQuery(ByVal NonSelectQuery As String, ByVal cnnTransaction As MySqlConnection) As Integer
                '   protected scope to make available only to child classes
    
                ExecuteNonQuery = 0
                mstrErrorMessage = ""
    
                Try
                    g_cmdUpdateAll.CommandText = NonSelectQuery
                    ExecuteNonQuery = g_cmdUpdateAll.ExecuteNonQuery()
                Catch ex As Exception
                    mstrErrorMessage = ex.Message
                End Try
               
    End Function
    This function resides in a base class called clsDataAccess. The clsConnection class inherits this class.

    I use this same code in a different program, the only difference is the opentransaction is done in a module and the executenonquery is done in each function.

    When this runs it adds the record before the commit happens. I'm confused as to what I'm doing wrong. Any help would be great!

    Thanks in advance!

    jim
    Last edited by Hack; 06-22-2012 at 02:19 PM. Reason: Added Code Tags

Similar Threads

  1. General Transaction Question (Commit)
    By jcb1269 in forum .NET
    Replies: 1
    Last Post: 06-21-2010, 09:39 AM
  2. Transaction commit
    By Prakash Dharan in forum VB Classic
    Replies: 2
    Last Post: 06-22-2001, 04:38 AM
  3. Re: Oracle Nested Transactions
    By Tim in forum Database
    Replies: 0
    Last Post: 06-20-2001, 09:21 AM
  4. Oracle Nested Transactions - or lack thereof
    By Andy Cortwright in forum Database
    Replies: 1
    Last Post: 06-20-2001, 09:09 AM
  5. Replies: 3
    Last Post: 03-01-2001, 10:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center