Results 1 to 3 of 3

Thread: when to close the connection and transaction?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2001
    Location
    MA, US
    Posts
    78

    when to close the connection and transaction?

    hi,

    my question is about the right place where I should close a connection and commit/rellback a transaction

    a page look like this
    ...
    try
    dim conn as sqlclient.sqlconnection(...)
    conn.open()
    ... define a transaction
    ... do database operations with the connection & transaction
    ... end of the operations
    ... commit the transaction
    conn.close()

    catch ex as exception
    ...if I try to rolback & close the transaction, it seems that those are not available here

    finally
    ...same (connection seems to not be available here)
    end try

    did I close the connection in the reght place?
    what is happening when something fail: when the connection will be closed, and when I can rollback the transaction?

    thank you,

    svatasoiu

  2. #2
    Hyperactive Member
    Join Date
    Jan 2003
    Location
    Cape Cod, US
    Posts
    292
    The conn is being dimmed inside the scope of the try block and as such isn't available within the catch. Don't ask me why but that's what I've observed...

    So you should be OK by doing the Dim before the try and you could always do the close in the "finally" while leaving the rollback and and commit in the catch and try.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2001
    Location
    MA, US
    Posts
    78

    Thumbs up

    thank you for your quick answer.

    you are right, I did not realized that by dim-ing in the try block, I restrict the availability of the connection

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width