DataReader connection error

Posts   
 
    
jeffkararo
User
Posts: 76
Joined: 06-Jan-2004
# Posted on: 14-Apr-2006 19:30:05   

I receive the following message

There is already an open DataReader associated with this Connection which must be closed first

but I am not sure what is causing it. It happens sporadically on the server. Any ideas on what may be causing this or possible solutions for preventing it?

Thanks

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39904
Joined: 17-Aug-2003
# Posted on: 14-Apr-2006 20:36:37   

Do you have a stacktrace with that exception?

Frans Bouma | Lead developer LLBLGen Pro
jeffkararo
User
Posts: 76
Joined: 06-Jan-2004
# Posted on: 17-Apr-2006 19:19:34   

No I do not. It is occurring in production during runtime.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39904
Joined: 17-Aug-2003
# Posted on: 17-Apr-2006 20:03:57   

jeffkararo wrote:

No I do not. It is occurring in production during runtime.

When you get the exception as you describe, it always comes with a stacktrace. Or do you log the exception somewhere and not the stacktrace?

Frans Bouma | Lead developer LLBLGen Pro
jeffkararo
User
Posts: 76
Joined: 06-Jan-2004
# Posted on: 18-Apr-2006 16:33:00   

Here is the StackTrace

System.InvalidOperationException: The SqlCommand is currently busy Open, Fetching.

Server stack trace: at System.Data.SqlClient.SqlCommand.set_Connection(SqlConnection value) at System.Data.SqlClient.SqlCommand.System.Data.IDbCommand.set_Connection(IDbConnection value) at SD.LLBLGen.Pro.ORMSupportClasses.Query.set_Connection(IDbConnection value) at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.ExecuteSingleRowRetrievalQuery(IRetrievalQuery queryToExecute, IEntityFields2 fieldsToFill, IFieldPersistenceInfo[] fieldsPersistenceInfo) at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityUsingFilter(IEntityFields2 fieldsToFetch, IFieldPersistenceInfo[] persistenceInfos, IRelationPredicateBucket filter) at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntity(IEntity2 entityToFetch, IPrefetchPath2 prefetchPath, Context contextToUse) at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntity(IEntity2 entityToFetch, IPrefetchPath2 prefetchPath) at HRImaging.Biz.RemoteServer.Server.GetOrganization(Int32 id, Boolean retrieveRelated) at System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(MethodBase mb, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs) at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)

Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at HRImaging.Biz.Interfaces.IRemoteServerBase.GetOrganization(Int32 id, Boolean retrieveRelated) at HRImaging.Win.Organization.OrganizationDetails.PopulateData() at HRImaging.Win.Organization.OrganizationDetails.PopulateForm() at HRImaging.Win.Organization.OrganizationDetails.OrganizationDetails_Load(Object sender, EventArgs e) at System.Windows.Forms.Form.OnLoad(EventArgs e) at HRImaging.Win.BaseForm.OnLoad(EventArgs e) at System.Windows.Forms.Form.OnCreateControl() at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at System.Windows.Forms.Control.CreateControl() at System.Windows.Forms.Control.WmShowWindow(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ScrollableControl.WndProc(Message& m) at System.Windows.Forms.ContainerControl.WndProc(Message& m) at System.Windows.Forms.Form.WmShowWindow(Message& m) at System.Windows.Forms.Form.WndProc(Message& m) at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39904
Joined: 17-Aug-2003
# Posted on: 18-Apr-2006 16:56:06   

Are you sharing the DataAccessAdapter object among requests to your remoted service? (so subsequent calls use the same dataaccessadapter object) ?

Frans Bouma | Lead developer LLBLGen Pro
jeffkararo
User
Posts: 76
Joined: 06-Jan-2004
# Posted on: 18-Apr-2006 17:32:50   

Yes

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39904
Joined: 17-Aug-2003
# Posted on: 18-Apr-2006 17:48:19   

jeffkararo wrote:

Yes

Then that's the cause.

Thread A starts a fetch, halfway through the resultset, the processor is passed to thread B. B then starts a fetch: boom.

Don't share a DataAccessAdapter among threads. If you have to, make sure just 1 thread can access the adapter object at any given moment.

Frans Bouma | Lead developer LLBLGen Pro