Results 1 to 7 of 7

Thread: [RESOLVED] Connection will not close in .net

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2001
    Posts
    430

    Resolved [RESOLVED] Connection will not close in .net

    As I watch in MySql Admin connections to server, I see the connection get made but it never disconnects. Is this different from VB6?

    Thanks

    Code:
     Private Sub WorkerThread1_EnterEvent(ByVal sender As System.Object, ByVal e As AxVBVoiceLib._WorkerThreadEvents_EnterEvent) Handles WorkerThread1.EnterEvent
            Dim conn As ADODB.Connection
            Dim rs As ADODB.Recordset
            conn = New ADODB.Connection
            rs = New ADODB.Recordset
            conn.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=ahmsys;UID=root;PWD=abc;"
            conn.Open()
            rs.Open("SELECT * FROM tenants WHERE ten_pin = '" & intPinNo & "'", conn)
            If rs.EOF Then
                lblValue.Text = "Invalid Pin Number"
            Else
                lblValue.Text = "Found Pin Number"
            End If
            rs.Close()
            rs = Nothing 
            conn.Close()
            conn = Nothing
        End Sub

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Connection will not close in .net

    I would guess that what you are seeing is an artifact of connection pooling. Your code is closing the connection, but to maximize efficiency, the app may quietly maintain the connection so that if you open the connection again soon afterwards, the overhead of the connection is reduced. I haven't studied it much, but re-establishing connections in .NET is faster because of connection pooling, and it may be what you are seeing. The speed comes from maintaining the connection (unless it gets kicked off).
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2001
    Posts
    430

    Re: Connection will not close in .net

    So there is no way to disconnect? If I don't disconnect the connection times out and the next timei go to the database it's locked out.

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Connection will not close in .net

    I haven't dealt with it, so I have no good answer for you. Look into connection pooling and you might find an answer. Otherwise, somebody who is familiar with that will probably wander by.
    My usual boring signature: Nothing

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2001
    Posts
    430

    Re: Connection will not close in .net

    Ok. Thanks. I'll hang around a bit.

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Connection will not close in .net

    You should move over to ADO.NET instead of classic ADO. When you use ADO.NET, you'll be allowed to close the connection as well as Dispose it so that the connection can be returned to the connection pool.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2001
    Posts
    430

    Re: Connection will not close in .net

    Good idea. I was just looking into it. Heck, something else to learn.

    Thanks everyone.

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