barnardj
09-12-2003, 08:52 AM
I have created a class to handle database opening, updates, retrieval etc and with the retreival function
I return a sqldatareader object to the calling object. This shown below:
Public Function getRecords(ByRef sql As String) As SqlDataReader
'** Get a collection of records
Dim dr As SqlDataReader
Try
opendb()
Dim cmd As New SqlCommand(sql, objConn)
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
Return dr
Catch ex As Exception
WriteToEventLog(ex.Message)
closedb()
Return Nothing
End Try
End Function
However I am unable to close the database connection as this will effectively close the datareader and so the calling object
and ASP will not be able to display the contents. This means that I am left with a 'hanging' database connection and so I have had errors
with the connection pool reaching its max.
Is there any way I can close the database connection in this function without affecting the datareader object?
Thanks in advance for any help
Judith
I return a sqldatareader object to the calling object. This shown below:
Public Function getRecords(ByRef sql As String) As SqlDataReader
'** Get a collection of records
Dim dr As SqlDataReader
Try
opendb()
Dim cmd As New SqlCommand(sql, objConn)
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
Return dr
Catch ex As Exception
WriteToEventLog(ex.Message)
closedb()
Return Nothing
End Try
End Function
However I am unable to close the database connection as this will effectively close the datareader and so the calling object
and ASP will not be able to display the contents. This means that I am left with a 'hanging' database connection and so I have had errors
with the connection pool reaching its max.
Is there any way I can close the database connection in this function without affecting the datareader object?
Thanks in advance for any help
Judith