Hi All,
I'm a novice at .net and am not so familiar with VB.net.
I've inherited some code which is causing the connection pool to overload.
This code below is what I think is causing the problem...it doesn't seem to close the connection.
The commented out lines I have tried to add but is casues an error.
Does anyone know how I can alter this code to close this connection. I suspect that because the actual result of the datareader is being returned that I won't be able to close the connection as control has passed out of the function.
Can anyone offer any advice?
protected function runDR(byval sqlStr as String) as SqlClient.SqlDataReader
Dim objConn As SqlConnection
Dim objCmd As SqlCommand
Dim myException As SqlException
Dim i as Int16
Try
objConn = New SqlConnection(connString)
objCmd = New SqlCommand(sqlStr, objConn)
objCmd.Connection.Open()
Return objCmd.ExecuteReader
Catch ex As SqlException
Return Nothing
'Finally
'objCmd.Dispose()
'objConn.Close()
End Try
End Function
I'm a novice at .net and am not so familiar with VB.net.
I've inherited some code which is causing the connection pool to overload.
This code below is what I think is causing the problem...it doesn't seem to close the connection.
The commented out lines I have tried to add but is casues an error.
Does anyone know how I can alter this code to close this connection. I suspect that because the actual result of the datareader is being returned that I won't be able to close the connection as control has passed out of the function.
Can anyone offer any advice?
protected function runDR(byval sqlStr as String) as SqlClient.SqlDataReader
Dim objConn As SqlConnection
Dim objCmd As SqlCommand
Dim myException As SqlException
Dim i as Int16
Try
objConn = New SqlConnection(connString)
objCmd = New SqlCommand(sqlStr, objConn)
objCmd.Connection.Open()
Return objCmd.ExecuteReader
Catch ex As SqlException
Return Nothing
'Finally
'objCmd.Dispose()
'objConn.Close()
End Try
End Function