Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2003
    Posts
    28

    Unanswered: Close passing connection object in procedure.

    Hello ,

    I create a sub procedure to manupulate data in database thru ADO connection. This connection object is passed to procedure as an reference argument (paCNN). In procedure, I dim a new connection object (say CNN) and set it to equal to argument.

    1) By close this CNN and set it to Nothing , Will it also close the connection object in calling program ?

    2) If this calling is within transaction control and connection object in calling program commit (or rollback) transaction, will system also commit (or rollback) manipulated data in this procedure ?

    My code look like this :

    Private Sub GetValue(paCNN as ADODB.Connection)
    Dim CNN As New ADODB.Connection
    Set CNN = paCNN
    ...
    ...
    CNN.Close : Set CNN = Nothing
    End Sub

    Thanks in advance

  2. #2
    Join Date
    Oct 2003
    Location
    Roanoke, Va
    Posts
    445

    Smile Re: Close passing connection object in procedure.

    Originally posted by suntisuk
    Hello ,

    I create a sub procedure to manupulate data in database thru ADO connection. This connection object is passed to procedure as an reference argument (paCNN). In procedure, I dim a new connection object (say CNN) and set it to equal to argument.

    1) By close this CNN and set it to Nothing , Will it also close the connection object in calling program ?

    2) If this calling is within transaction control and connection object in calling program commit (or rollback) transaction, will system also commit (or rollback) manipulated data in this procedure ?

    My code look like this :

    Private Sub GetValue(paCNN as ADODB.Connection)
    Dim CNN As New ADODB.Connection
    Set CNN = paCNN
    ...
    ...
    CNN.Close : Set CNN = Nothing
    End Sub

    Thanks in advance


    1) No it will not close the original connection object. You have created a new object reference and closed it and set it to nothing. The original stays open.

    2) Don't have enough experience with transaction processing to say for sure but I think whatever occurs within the BeginTrans and CommitTrans will be undone with a Rollback.

    Gregg

  3. #3
    Join Date
    Oct 2003
    Posts
    706

    Re: Close passing connection object in procedure.

    [i]
    1) By close this CNN and set it to Nothing , Will it also close the connection object in calling program ?

    2) If this calling is within transaction control and connection object in calling program commit (or rollback) transaction, will system also commit (or rollback) manipulated data in this procedure?
    Connections, like many other things, are internally "reference-counted." Several variables can point to the same connection, e.g., at the same time, so the system keeps track of how many "live" variables presently refer to it. The connection does not completely cease to exist until all references are closed.

    Transactions are a completely separate animal. They are known to the database engine, not VB per-se, and whenever you have one and "commit" it (no matter who started it and no matter who committed), "that's it."

    Transactions can be nested. In other words, you can start a transaction, then start another one inside of that one, commit the first, roll-back the outermost one, and .. the net effect is a rollback. As a design point, "don't roll back someone else's transaction." This creates unwanted functional dependencies ("bugz!") between modules that are essentially impossible to diagnose. They can also cause runtime errors.
    ChimneySweep(R): fast, automatic
    table repair at a click of the
    mouse! http://www.sundialservices.com

Posting Permissions

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