Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. SQL Connection not released (VB.Net)

SQL Connection not released (VB.Net)

Scheduled Pinned Locked Moved ASP.NET
databasecsharpsql-serversysadmin
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    Zee_Zee
    wrote on last edited by
    #1

    Hello friends, I am facing a strange problem here. I have a class with a private member of type string. This is actually a connection string. I've a public method getConnection that creates an instance of sqlConnection and returns it. I simply set reference to this returned object in my pages and after using this connection I close this connection using the reference. But when I go and check "connections using this database" through sql server enterprise manager it shows me 5 connections there even if I close the application. I am pasting the code snippets to make you understand the situation more clearly. ''''''''''''''''''''This is my vb class''''''''''''''''' Public Class DBConnection Private connString As String Public Sub New() connString = "Server=myPC; Database=testDB;UID=sa;Password=;" End Sub Public Function getConnection() As SqlClient.SqlConnection Dim connObj As New SqlConnection(connString) connObj.Open() Return connObj End Function End Class ''''''''''''''''''''This is code behind file''''''''''''''''' Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here populatePendingConsignmentsGrid() End Sub Private Sub populatePendingConsignmentsGrid() Dim objConn As SqlClient.SqlConnection Dim objDR As SqlClient.SqlDataReader Dim objConsignment As New Consignment Dim i As New Integer Dim consignmentObj As New Consignment Dim arrList As ArrayList Dim objDBConnection As New DBConnection objConn = objDBConnection.getConnection() objConsignment.getAllPendingConsignmentsDR(objConn, objDR) PendingConsignmentsDG.DataSource = objDR PendingConsignmentsDG.DataBind() objDR.Close() objConn.Close() objConn.Dispose() End Sub '''''''''''''''''''''''''''''''''''''''''''''''''''' With best regards, Zee_Zee

    Z 1 Reply Last reply
    0
    • Z Zee_Zee

      Hello friends, I am facing a strange problem here. I have a class with a private member of type string. This is actually a connection string. I've a public method getConnection that creates an instance of sqlConnection and returns it. I simply set reference to this returned object in my pages and after using this connection I close this connection using the reference. But when I go and check "connections using this database" through sql server enterprise manager it shows me 5 connections there even if I close the application. I am pasting the code snippets to make you understand the situation more clearly. ''''''''''''''''''''This is my vb class''''''''''''''''' Public Class DBConnection Private connString As String Public Sub New() connString = "Server=myPC; Database=testDB;UID=sa;Password=;" End Sub Public Function getConnection() As SqlClient.SqlConnection Dim connObj As New SqlConnection(connString) connObj.Open() Return connObj End Function End Class ''''''''''''''''''''This is code behind file''''''''''''''''' Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here populatePendingConsignmentsGrid() End Sub Private Sub populatePendingConsignmentsGrid() Dim objConn As SqlClient.SqlConnection Dim objDR As SqlClient.SqlDataReader Dim objConsignment As New Consignment Dim i As New Integer Dim consignmentObj As New Consignment Dim arrList As ArrayList Dim objDBConnection As New DBConnection objConn = objDBConnection.getConnection() objConsignment.getAllPendingConsignmentsDR(objConn, objDR) PendingConsignmentsDG.DataSource = objDR PendingConsignmentsDG.DataBind() objDR.Close() objConn.Close() objConn.Dispose() End Sub '''''''''''''''''''''''''''''''''''''''''''''''''''' With best regards, Zee_Zee

      Z Offline
      Z Offline
      Zafar Iqbal
      wrote on last edited by
      #2

      Hi, This is due to connection pooling option available by default in .Net. ADO.Net manages a pool of connection, and this pool is identified by the connection string you specify. If you create connections as you have specified then new connection's object would be added in the pool. These objects are released when anything connected through these connections is properly disposed and then these connections are also disposed propery and not used elsewhere. However ADO.Net takes its own decision when to finally release these connection. Try reading some article on connection pooling either from msdn or some are also available on this site.

      Z 1 Reply Last reply
      0
      • Z Zafar Iqbal

        Hi, This is due to connection pooling option available by default in .Net. ADO.Net manages a pool of connection, and this pool is identified by the connection string you specify. If you create connections as you have specified then new connection's object would be added in the pool. These objects are released when anything connected through these connections is properly disposed and then these connections are also disposed propery and not used elsewhere. However ADO.Net takes its own decision when to finally release these connection. Try reading some article on connection pooling either from msdn or some are also available on this site.

        Z Offline
        Z Offline
        Zee_Zee
        wrote on last edited by
        #3

        Thanks a lot friend I really appreicate your help Regards, Zee_Zee

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups