S
sri_san
Hello,
I have a bunch of similar functions as listed below. This one
returns a string but lot of functions return datareader. I close the
reader, the connection and set it to nothing but the connection still
seems to be hanging.
-------------------------
Public Function Login(ByVal email As String, ByVal password As
String) As String
Dim myConnection As New
SqlConnection(ConfigurationSettings.AppSettings("connectionString"))
Dim myCommand As New SqlCommand("UserLogin", myConnection)
Dim myreader As SqlDataReader
' Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure
' Add Parameters to SPROC
Dim parameterEmail As New SqlParameter("@Email",
SqlDbType.NVarChar, 100)
parameterEmail.Value = email
myCommand.Parameters.Add(parameterEmail)
Dim parameterPassword As New SqlParameter("@Password",
SqlDbType.NVarChar, 50)
parameterPassword.Value = password
myCommand.Parameters.Add(parameterPassword)
' Open the database connection and execute the command
myConnection.Open()
myreader =
myCommand.ExecuteReader(CommandBehavior.CloseConnection)
'myConnection.Close()
If myreader.HasRows Then
myreader.Read()
Return CStr(myreader("name")) & "," &
CInt(myreader("userid"))
Else
Return String.Empty
End If
myreader.Close()
myreader = Nothing
If myConnection.State = ConnectionState.Open Then
myConnection.Close()
End If
myConnection = Nothing
End Function
I have a bunch of similar functions as listed below. This one
returns a string but lot of functions return datareader. I close the
reader, the connection and set it to nothing but the connection still
seems to be hanging.
-------------------------
Public Function Login(ByVal email As String, ByVal password As
String) As String
Dim myConnection As New
SqlConnection(ConfigurationSettings.AppSettings("connectionString"))
Dim myCommand As New SqlCommand("UserLogin", myConnection)
Dim myreader As SqlDataReader
' Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure
' Add Parameters to SPROC
Dim parameterEmail As New SqlParameter("@Email",
SqlDbType.NVarChar, 100)
parameterEmail.Value = email
myCommand.Parameters.Add(parameterEmail)
Dim parameterPassword As New SqlParameter("@Password",
SqlDbType.NVarChar, 50)
parameterPassword.Value = password
myCommand.Parameters.Add(parameterPassword)
' Open the database connection and execute the command
myConnection.Open()
myreader =
myCommand.ExecuteReader(CommandBehavior.CloseConnection)
'myConnection.Close()
If myreader.HasRows Then
myreader.Read()
Return CStr(myreader("name")) & "," &
CInt(myreader("userid"))
Else
Return String.Empty
End If
myreader.Close()
myreader = Nothing
If myConnection.State = ConnectionState.Open Then
myConnection.Close()
End If
myConnection = Nothing
End Function