If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Visual Basic > Transaction in vb.net

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-25-10, 18:49
kpeeroo kpeeroo is offline
Registered User
 
Join Date: Jul 2009
Posts: 143
Transaction in vb.net

Hi

I have a problem with implementing transactions with my vb.net application. My code goes like this:

public Function processCoursePayment()
---
--- code
---

mancosa.payCourse()

---
--- code
---
End Function

Code:
public Function payCourse()
Dim sd As DataSet1TableAdapters.StudentPaymentTableAdapter = New DataSet1TableAdapters.StudentPaymentTableAdapter
        Dim dsPayCourse As DataSet1.StudentPaymentDataTable = New DataSet1.StudentPaymentDataTable
        Dim connection = sd.Connection
        Dim transaction As SqlTransaction
        Dim studentRow As DataRow = dsPayCourse.NewRow
        studentRow.Item("amount") = amount
        studentRow.Item("date") = payDate
        studentRow.Item("studentID") = studentID
        studentRow.Item("courseFeesID") = courseFeesID
        studentRow.Item("paymentMethodID") = paymentMethodID
        dsPayCourse.AddStudentPaymentRow(studentRow)
        Dim count As Integer = dsPayCourse.Count
        connection.Open()
        transaction = connection.BeginTransaction(IsolationLevel.Serializable)
        sd.Adapter.UpdateCommand.Transaction = transaction
        sd.Adapter.InsertCommand.Transaction = transaction
        Try
            sd.Adapter.Update(dsPayCourse)
            dsPayCourse.AcceptChanges()
            transaction.Commit()
        Catch ex As Exception
            transaction.Rollback()
            Console.WriteLine(ex.Message)
        Finally
            connection.Close()
        End Try
End Function
I had the exception that 'The Transaction property of the command has not been initialized.' But this is solved once I inserted the
'sd.Adapter.InsertCommand.Transaction = transaction' part.

However the problem is that when I run in debugger mode and I stop the running of the program before the commit() part, my data table still gets updated and the results are in the database, hence it has not performed the rollback properly. Also, like shown above when the payCourse() function exits, there are still code to be run in the main processCoursePayment() function. So I would want that if a rollback occured in the inner function, then the whole processCoursePayment() is aborted.

Anyone can advise on this please? Thanks.

Last edited by kpeeroo; 10-25-10 at 19:03.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On