DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Releasing Un managed Resources from an object

  1. #1
    Philip Guest

    Releasing Un managed Resources from an object


    Hi,

    I have a problem in releasing database connections from an object after
    use. I am using SQL Server and ADO ver 2.5

    The following code is in VB6

    Dim objConn As ADODB.Connection
    Set objConn = New ADODB.Connection
    objConn.Open("PROVIDER=SQLOLEDB;Server=HomePc;_
    Database=InvestracTest;User Id=sa;Password=sa")
    objConn.Close
    Set objConn = Nothing

    If i run the above code in vb6, the connection object is released once the
    procedure ends. This can be checked in SQL Server using the
    CurrentActivity / ProcessInfo node.

    However if the same code is run in VB.Net, the connection object does not
    get released even though the connection is explicitly closed and the connection
    variable is set to nothing

    The vb.net code is as follows

    Dim objConn As ADODB.Connection
    objConn = New ADODB.Connection()
    objConn.Open("PROVIDER=SQLOLEDB;Server=HomePc; _
    Database=InvestracTest;User Id=sa;Password=sa")
    objConn.Close()

    If the above block of code is pasted multiple times withing the same procedure,
    multiple connections remain open after the procedure ends.

    Any ideas on how to release the connections in VB.Net






  2. #2
    Kathleen Dollard Guest

    Re: Releasing Un managed Resources from an object

    Philip,

    You are seeing connection pooling, although I am not sure why you are
    picking up the extra connections instead of reusing the pooled connection.
    My guess is that you are just hitting it too fast and that in a real world
    application the connection would be reused.

    If you don't like pooling, which offers significant performance benefits,
    turn it off.

    Kathleen

    "Philip" <philip.morley@bmb.com.bh> wrote in message
    news:3e1ea6ca$1@tnews.web.devx.com...
    >
    > Hi,
    >
    > I have a problem in releasing database connections from an object after
    > use. I am using SQL Server and ADO ver 2.5
    >
    > The following code is in VB6
    >
    > Dim objConn As ADODB.Connection
    > Set objConn = New ADODB.Connection
    > objConn.Open("PROVIDER=SQLOLEDB;Server=HomePc;_
    > Database=InvestracTest;User Id=sa;Password=sa")
    > objConn.Close
    > Set objConn = Nothing
    >
    > If i run the above code in vb6, the connection object is released once the
    > procedure ends. This can be checked in SQL Server using the
    > CurrentActivity / ProcessInfo node.
    >
    > However if the same code is run in VB.Net, the connection object does not
    > get released even though the connection is explicitly closed and the

    connection
    > variable is set to nothing
    >
    > The vb.net code is as follows
    >
    > Dim objConn As ADODB.Connection
    > objConn = New ADODB.Connection()
    > objConn.Open("PROVIDER=SQLOLEDB;Server=HomePc; _
    > Database=InvestracTest;User Id=sa;Password=sa")
    > objConn.Close()
    >
    > If the above block of code is pasted multiple times withing the same

    procedure,
    > multiple connections remain open after the procedure ends.
    >
    > Any ideas on how to release the connections in VB.Net
    >
    >
    >
    >
    >




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