G
Guest
greeting,
attach below are my codes for a sqldatareader method, it returns a
sqldatareader. if you notice, i have my close connection in the finally
method. anyway, since its returning a sqldatareader, i cannt read it and i
get an error stating that it cannot be read while the connection is close, if
i comment the connection.close method, it works fine. but how about the
connection? how to i close it? thanks in advance for your reply.
Public Function DistiByLogin(ByVal strLoginId As String) As SqlDataReader
Dim objGetConn As New DATTConnection.DATTDataAccess
Dim objConn As New SqlConnection
Dim objCmd As New SqlCommand
Dim objErr As New ErrorHandler
Dim objReader As SqlDataReader
Try
objConn = objGetConn.GetSQLConnection(objErr)
objConn.Open()
objCmd.Connection = objConn
objCmd.CommandType = CommandType.StoredProcedure
objCmd.CommandText = "pr_DISTI_CMF_NO"
objCmd.Parameters.Add("@LoginId", SqlDbType.NVarChar, 80).Value
= strLoginId
objReader = objCmd.ExecuteReader
Return objReader
Catch ex As Exception
Finally
objConn.Close()
objConn.Dispose()
objCmd.Dispose()
objGetConn = Nothing
objCmd = Nothing
End Try
attach below are my codes for a sqldatareader method, it returns a
sqldatareader. if you notice, i have my close connection in the finally
method. anyway, since its returning a sqldatareader, i cannt read it and i
get an error stating that it cannot be read while the connection is close, if
i comment the connection.close method, it works fine. but how about the
connection? how to i close it? thanks in advance for your reply.
Public Function DistiByLogin(ByVal strLoginId As String) As SqlDataReader
Dim objGetConn As New DATTConnection.DATTDataAccess
Dim objConn As New SqlConnection
Dim objCmd As New SqlCommand
Dim objErr As New ErrorHandler
Dim objReader As SqlDataReader
Try
objConn = objGetConn.GetSQLConnection(objErr)
objConn.Open()
objCmd.Connection = objConn
objCmd.CommandType = CommandType.StoredProcedure
objCmd.CommandText = "pr_DISTI_CMF_NO"
objCmd.Parameters.Add("@LoginId", SqlDbType.NVarChar, 80).Value
= strLoginId
objReader = objCmd.ExecuteReader
Return objReader
Catch ex As Exception
Finally
objConn.Close()
objConn.Dispose()
objCmd.Dispose()
objGetConn = Nothing
objCmd = Nothing
End Try