locked
The transaction associated with the current connection has completed but has not been disposed RRS feed

  • Question

  • User351619809 posted

    Hi All,

    I opened the connection to the database. I am looping through several lines of code and then I am closing the connection> below is my code:

    Conn.opne()   
    
    For Each mycode As code In myDataHeader.CodeList
                    SaveData()
                    If Len(ErrorMessage) > 0 Then
                        'Exit Try
    
                    End If
                Next
    
    
    For Each mycodeTest As code In myDataHeader.CodeListTest
                    SaveData()
                    If Len(ErrorMessage) > 0 Then
                        'Exit Try
    
                    End If
                Next
    
    
    For Each mycodeTestRaw As code In myDataHeader.CodeListTestRaw
                    SaveData()
                    If Len(ErrorMessage) > 0 Then
                        'Exit Try
    
                    End If
                Next
    
    Conn.close()


    In the last statement when I am inserting the data in the database, I am getting an error saying

    "

    "The transaction associated with the current connection has completed but has not been disposed. The transaction must be disposed before the connection can be used to execute SQL statements."

    Is it possible to avoid this statement.

     

    any help will be appreciated.In my connection string, the connect time out = 300

     

    Tuesday, July 14, 2015 2:18 PM

Answers

  • User-84896714 posted

    Hi anjaliagarwal5,

    Thank you for your post. Did you use transaction in your code. For example did you use TransactionScope class or BeginTransaction method? If you use it, you could close the connection after transaction closed.

    Best Regards,
    Wang Li

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 15, 2015 5:47 AM

All replies

  • User-84896714 posted

    Hi anjaliagarwal5,

    Thank you for your post. Did you use transaction in your code. For example did you use TransactionScope class or BeginTransaction method? If you use it, you could close the connection after transaction closed.

    Best Regards,
    Wang Li

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 15, 2015 5:47 AM
  • User351619809 posted

    yes, I just used the transaction scope in my code and now it is working.

    Thursday, July 23, 2015 2:22 PM