|
-
Feb 4th, 2009, 12:49 PM
#1
Thread Starter
Hyperactive Member
[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
-
Feb 4th, 2009, 12:54 PM
#2
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
 
-
Feb 4th, 2009, 01:15 PM
#3
Thread Starter
Hyperactive Member
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.
-
Feb 4th, 2009, 03:15 PM
#4
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
 
-
Feb 5th, 2009, 02:09 PM
#5
Thread Starter
Hyperactive Member
Re: Connection will not close in .net
Ok. Thanks. I'll hang around a bit.
-
Feb 5th, 2009, 02:12 PM
#6
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.
-
Feb 5th, 2009, 02:21 PM
#7
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|