A correct implementation of StateChange

A correct implementation of StateChange

Postby ucelenli » Fri 08 Nov 2013 07:35

After upgrading to 7.x , I started to get errors saying "Connection must be opened". When I dug a little deep I found out this ticket on Codeplex EF project;

http://entityframework.codeplex.com/workitem/1725
In EF6 we subscribe to the DbConnection.StateChange event to keep the State of EntityConnection and the underlying StoreConnection in sync. However if the custom DbConnection does not correctly fire the event the state of the EntityConnection is different from the state of the underlying store connection provided by user. In this case we will first assert in the EnsureContextIsEnlistedInCurrentTransaction method (see below) and then throw an InvalidOperationException saying "The connection is not open.". The message can be surprising since when the user looks at his connection it is actually open and also if you set breakpoints on Open() and Close() methods you will see that Open() was called but Close() was not. We throw the exception since this the EntityConnection whose state is closed. Note that before EF6 we did not use the StateChange event, so if someone is trying to move an EF5 project that was using a wrapping provider to EF6 he will very likely hit this issue. We should replace the assert with an exception hinting that a correct implementation StateChange is required.


In this case is there an error, or a wrong implementation on Devart DotConnect, or my code? Should I handle this connectionstate or do you guys have to patch this ?

Please advise.
ucelenli
 
Posts: 5
Joined: Thu 09 Jun 2011 16:19

Re: A correct implementation of StateChange

Postby Shalex » Mon 11 Nov 2013 18:05

Could you please send us a small test project so that we can reproduce the problem in our environment?
Shalex
Devart Team
 
Posts: 7659
Joined: Thu 14 Aug 2008 12:44

Re: A correct implementation of StateChange

Postby ucelenli » Mon 11 Nov 2013 21:54

Did you see what I have quoted?
ucelenli
 
Posts: 5
Joined: Thu 09 Jun 2011 16:19

Re: A correct implementation of StateChange

Postby Shalex » Tue 12 Nov 2013 12:33

Yes, we did. Our provider implements the DbConnection.StateChange event. If you encounter the scenario where it works incorrectly for some reason, please send us a small test project so that we can reproduce the problem in our environment.
Shalex
Devart Team
 
Posts: 7659
Joined: Thu 14 Aug 2008 12:44


Return to dotConnect for PostgreSQL