Using VB.Net and SQL Server 2008 R2:
I have recently had a database that using sp_who2 reflects a connection ".Net SqlClient Data Provider" is still active even though the .Net application has closed and disposed of all connections.
The code looks like this:
Imports System.Data.SqlClient
Private Sub TestSQLConnection()
Dim strConnection As String
strConnection = "Server=MyServer;UID=User;PWD=Password;Database=MyDatabase"
Dim conn As New SqlConnection(strConnection)
conn.Open()
conn.Close()
conn.Dispose()
GC.Collect()
GC.WaitForPendingFinalizers()
End Sub
And when i look at SQL Server usng sp_who2 after running the application (look at the bold .NetSQLClientDataProvider)
SPID Status Login HostName BlkBy DBName Command CPUTime DiskIO LastBatch ProgramName SPID REQUESTID
57 sleeping sa YOUR-PC . master AWAITING COMMAND 0 0 07/19 12:38:48 *.Net SqlClient Data Provider* 57 0
Only when i actually close the APPLICATION will the .Net SQLClient Data connection be removed from the view. What i am concerned about is the following: 1. what affect are these process's having on my database from a resource perspective and why is the connection reflected and sleeping. 2. When i try detach a database i se that 1 connection is active but the code has closed and disposed.