ASP.NET / SQL2005 Close Connection
Posted on 2011-03-01
When executing my web application I noticed that the database connection stays opened even after I close the connection. I see this by running the sp_who in SQL2005. I listed below a piece of code that shows I closed the connection and even try to set it to nothing. Is there something I am missing? I am ready to deploy but do not want to run into any connection issues. There will be roughly 100 uses accessing the application.
Function GetUserNameByID(ByVal lUserID As Long) As String
Dim ds As New DataSet
Dim cn = New SqlConnection(msSQLConnectionString)
Dim cmd As New SqlCommand("getUserByID", cn)
cmd.CommandType = CommandType.StoredProcedure
'...Set up parameter for stored procedure
cmd.Parameters("@UserID").Value = lUserID
Dim Reader As SqlDataReader = cmd.ExecuteReader
GetUserNameByID = Reader("Fullname").ToString
Reader = Nothing
Catch ex As Exception
GetUserNameByID = ""
cn = Nothing