Unable to close database connection after returnin

Results 1 to 2 of 2

Thread: Unable to close database connection after returnin

  1. #1
    Join Date
    Dec 1969

    Default Unable to close database connection after returnin

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

  2. #2

    Default RE: Unable to close database connection after retu

    Ya, by using a DataSet instead of a DataReader.<BR><BR>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/daab-rm.asp<BR><BR>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/daag.asp

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts