open DataReader associated with this Connection

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have been recently receiving the System.InvalidOperartionException with
the message "There is already an open DataReader associated with this
Connection which must be closed first." from my business application. The
fact is I haven't used DataReader in my application. All data management is
done with dataset. The stack trace clearly reveals that this happens when
Fill method is called on the dataadapter object. This exception happens when
I had about 15 users concurrently testing the web application. The ADO.NET
code is coded within a .NET remote application deployed in IIS 6.0 servers on
W2K3 server. I think this is a concurrency problem and I read in one of the
newsgroups that if I handle the FillError event and set the continue property
to true I can overcome this problem.

First of all, I want to understand why Fill method led to this error and I
would also like to know if there is any other way other than fill error event
handler to prevent this exception crashing application.

Any suggesstions or pointers will be greatly appreciated.

Thank you.
Magdelin
 
Magdelin,
The Fill method on the dataAdapter internally calls the ExecuteReader method
to get the result set from the Server to the client. Hence you are seeing
this exception from the Fill method.
Thanks,
Sushil.
 
Consider that the Fill method uses the DataReader behind the scenes. I
expect that when the Fill fails (for some reason), the DataReader is not
getting torn down correctly (if at all). I would make sure you're using the
1.1 version of the Framework.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
Thanks for the reply. I am aware that the error was because of the fill
method calling execute reader method. The inserted stack trace provided
sufficient information about it. All I need to know is why this would happen
in the first place and how to prevent it.

StackTrace Information
*********************************************
at System.Data.SqlClient.SqlCommand.ValidateCommand(String method,
Boolean executing)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior)
at
System.Data.SqlClient.SqlCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.FillFromCommand(Object data, Int32
startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable, IDbCommand
command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
at Us.Idhw.Rms.Biz.Util.SqlDAO.ExecuteDataset(String storedProcName,
SqlParameter[] commandParameters)

Thank You
Magdelin
 
Hi Magdelin,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you're receiving an
InvalidOperationException when Filling the DataSet. If there is any
misunderstanding, please feel free to let me know.

Just as Sushil mentioned, Fill method internally calls ExecuteReader to
retrieve data from database. We can use some ways to provent this from
happening.

1. Create a connection for each Fill operation instead of using a shared
static connection. But this will
2. Lock the connection object when filling.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Kevin,
1. Create a connection for each Fill operation instead of using a shared
static connection. But this will
2. Lock the connection object when filling.
I am curious if this is the problem, because I find it a very good
deduction.
(Or do you have more information about the problem?)

Cor
 
Thanks for the suggestion. I am using the right version of .NET framework.
Like Kevin had suspected I am not using new connection for each fill. Since I
have configured my remote component which performs all database operations to
use Singleton instantiation, I think I am getting into concurrency issues. I
am planning to use a new connection object for each Fill or Update to
overcome this error.

Magdelin
 
Back
Top