Page 1 of 1

A correct implementation of StateChange

Posted: Fri 08 Nov 2013 07:35
by ucelenli
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.

Re: A correct implementation of StateChange

Posted: Mon 11 Nov 2013 18:05
by Shalex
Could you please send us a small test project so that we can reproduce the problem in our environment?

Re: A correct implementation of StateChange

Posted: Mon 11 Nov 2013 21:54
by ucelenli
Did you see what I have quoted?

Re: A correct implementation of StateChange

Posted: Tue 12 Nov 2013 12:33
by Shalex
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.