Print Page | Close Window

new EntityManager Exception after detach/attach of a Database

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2564
Printed Date: 29-Jul-2026 at 5:42pm


Topic: new EntityManager Exception after detach/attach of a Database
Posted By: PascalSchmitt
Subject: new EntityManager Exception after detach/attach of a Database
Date Posted: 16-Mar-2011 at 6:47am

Hi,
We have an application using DevForce WinClient over a SQL Express database. The database is for the end user seen as "a project". He can manage several projects in its application, move them,  delete them, rename, etc...
So basically a SQL Express database file (the .mdf file) is a project.
To let the user manage the projects (the database files) every time a project is closed, we detach the database file from SQL Express (using this method: http://newsgroups.derkeiler.com/Archive/Comp/comp.databases.ms-sqlserver/2008-01/msg00244.html - http://newsgroups.derkeiler.com/Archive/Comp/comp.databases.ms-sqlserver/2008-01/msg00244.html
Before its opening, the database file is attached using an AttachDbFileName property in the connexion string.

This seems to work just fine.

The problem is when we re-open a database file that was attached and detached, and a new EntityManager is created, the first request that is done again the EntityManager throws an EntityServerException.
It is like the underlying layers of the EntityManager still has some static handles or informations on the connection that was used before the detach of the database (see stacktrace hereafter), whatever the instance of the EntityManager he is using.
If the exception thrown by DevForce is catched an nothing more is done, we are able to do C/R/U/D operations on the database and everything seems to work (?)

My question: is there a way to let Devforce know that a detach of a database has occured, or a way to reset the underlying informations that he keeps on the connections ?

Thank you.
 
----------
Stack Trace :    at IdeaBlade.EntityModel.EntityManager.HandleEntityServerException(Exception ex, Boolean tryToHandle, PersistenceOperation operation)
   at IdeaBlade.EntityModel.EntityManager.ExecuteServerQuery(IEntityQuerySurrogate entityQuery)
   at IdeaBlade.EntityModel.EntityManager.ExecuteFetch(IEntityFinder finder)
   at IdeaBlade.EntityModel.EntityQueryFinder.Execute()
   at IdeaBlade.EntityModel.EntityManager.ExecuteQueryCore(IEntityQuery query, Boolean isAsync)
   at IdeaBlade.EntityModel.EntityManager.ExecuteQueryForObject(IEntityQuery query)
   at IdeaBlade.EntityModel.EntityQuery`1.System.Linq.IQueryProvider.Execute[TResult](Expression expression)
   at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source)

    Inner Exception
    ---------------
    Type : System.Data.EntityCommandExecutionException, System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
    Message : An error occurred while executing the command definition. See the inner exception for details.
    Source : IdeaBlade.EntityModel
    Help link :
    Stack Trace :    at IdeaBlade.EntityModel.EntityServerProxy.CheckConnection(Exception e)
       at IdeaBlade.EntityModel.EntityServerProxy.Fetch(SessionBundle bundle, IEntityQuerySurrogate query)
       at IdeaBlade.EntityModel.EntityManager.ExecuteServerQuery(IEntityQuerySurrogate entityQuery)

        Inner Exception
        ---------------
        Type : System.Data.SqlClient.SqlException, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
        Message : A transport-level error has occurred when sending the request to the server. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.)
        Source : .Net SqlClient Data Provider
        Help link :
        Stack Trace :    at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
           at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
           at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
           at System.Data.SqlClient.TdsParserStateObject.WriteSni()
           at System.Data.SqlClient.TdsParserStateObject.WritePacket(Byte flushMode)
           at System.Data.SqlClient.TdsParserStateObject.ExecuteFlush()
           at System.Data.SqlClient.TdsParser.TdsExecuteSQLBatch(String text, Int32 timeout, SqlNotificationRequest notificationRequest, TdsParserStateObject stateObj)
           at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
           at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
           at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
           at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
           at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
           at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
           at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)

 




Replies:
Posted By: DenisK
Date Posted: 16-Mar-2011 at 9:11pm
Hi PascalSchmitt;

Have you tried calling System.Data.SqlClient.SqlConnection.ClearAllPools() to reset the connection pool?


Posted By: PascalSchmitt
Date Posted: 18-Mar-2011 at 5:56am
Hi Denis,

Sorry for the late answer, did not get the email alert.

Yes, now it works, thank you for the tip !




Print Page | Close Window