Open DataReader error

Results 1 to 2 of 2

Thread: Open DataReader error

  1. #1
    Join Date
    Dec 1969

    Default Open DataReader error

    On the website that I&#039;m building, sometimes when a page comes up we get the error &#039;There is already an open datareader associated with this connection&#039;. If the page is then refreshed, it works fine and there isn&#039;t any consistency with how this error comes up. We&#039;re using connection pooling to connect to the database, so this may have something to do with it.<BR><BR>In every case, there is no way that this open datareader could come from anywhere but a previous page or a previous loading of the same apge and even when datareaders are always opened in a try block and closed in the finally block, it still happens from time to time.<BR><BR>In every case, the datareader should have been closed. Is there anyway to check to see if there is an open datareader associated with a connection and close it? We don&#039;t want to have to get rid of the connection pooling, so we just want to kill any extraneous datareaders that haven&#039;t been disposed of properly.

  2. #2
    Join Date
    Dec 1969

    Default RE: Open DataReader error

    Can you post your database code? I used to come across a similar error (if not the same), but it went away completely after I started explicitly disposing of my objects.<BR><BR>Do not get rid of connection pooling.<BR><BR>Here&#039;s some sample syntax to try out:<BR><BR> Public Function GetAllQueues() As ArrayList<BR> Dim objConn As New SqlConnection(ConfigurationSettings.AppSettings("D SN"))<BR> Dim _Return As New ArrayList()<BR><BR> Dim objCmd As New SqlCommand("spGetAllQueues", objConn)<BR> objCmd.CommandType = CommandType.StoredProcedure<BR><BR> objConn.Open()<BR> Try<BR> Dim objRdr As SqlDataReader<BR> objRdr = objCmd.ExecuteReader()<BR><BR> While objRdr.Read()<BR> Dim _Queue As New Queue()<BR> _Queue.QueueName = objRdr.Item("QueueName").ToString<BR> _Queue.QueueCode = objRdr.Item("QueueCode").ToString<BR> _Return.Add(_Queue)<BR> End While<BR><BR> Return _Return<BR> Catch ex As Exception<BR> Return _Return<BR> Finally<BR> objConn.Close()<BR> objConn.Dispose()<BR> objConn = Nothing<BR> End Try<BR> End Function<BR><BR><BR>--------------------------<BR><BR>I know some of it is redundant and possibly one of the final three commands might be able to go away, but after scouring the web, I found a lot of posted evidence that backs up using all three. And the main thing is that the change made my connection problems go away.<BR><BR>If anyone has any better advice, I&#039;m open to it myself, but that should get rid of the lock on your connection objects.<BR><BR>HTH,<BR>Willis<BR>

Posting Permissions

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