A correct implementation of StateChange

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for PostgreSQL
Post Reply
ucelenli
Posts: 5
Joined: Thu 09 Jun 2011 16:19

A correct implementation of StateChange

Post by 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.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: A correct implementation of StateChange

Post by 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?

ucelenli
Posts: 5
Joined: Thu 09 Jun 2011 16:19

Re: A correct implementation of StateChange

Post by ucelenli » Mon 11 Nov 2013 21:54

Did you see what I have quoted?

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: A correct implementation of StateChange

Post by 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.

Post Reply