At the moment 'OAConnection.StoreConnection' property returns a thin wrapper over the actual ADO connection instance (SQLiteConnection in case you are working with the SQLite backend) ; this is the LoggingDbConnection. This type is defined in the 'Telerik.OpenAccess.Runtime' assembly.
The actual event handler is added to this instance and not the ADO connection instance. We will fix this so that the actual ADO connection instance is returned.
In the meantime, as a workaround, you can add a reference to the 'Telerik.OpenAccess.Runtime' assembly and wrap the call to 'model.StoreConnection.StoreConnection' as follows -
var connection = LoggingDbConnection.UnWrap(model.StoreConnection.StoreConnection)
connection.StateChange += ConnectionStateChange;
connection.Disposed += ConnectionDisposed;
This should fix the problem.
Some additional information on how connections are handled.
OpenAccess maintains a connection pool from which connections are obtained by the context when they are required and returned back after using it. When you obtain the actual ADO connection using 'OAConnection.StoreConnection', OpenAccess disowns the ADO connection because it does not have any control on what operations might be performed on the connection. So if the OAConnection instance is disposed in user code the underlying ADO will be closed , but it is the users responsibility to dispose the actual ADO connection once he has finished using it. Here is a what happens at each step of your code -
using (EntitiesModel model = new EntitiesModel(Settings1.Default.ConnString))
using(OAConnection oaConnection = model.Connection)//obtain a connection from the connection pool
DbConnection adoConnection = oaConnection.StoreConnection;//remove the connection from the pool and disown it. Users responsiblity to close and dispose the adoConnection
adoConnection.StateChange += ConnectionStateChange;
adoConnection.Disposed += ConnectionDisposed;
}//dispose OAConnection.adoConnection closed but not disposed
Note that if you do not dispose the OAConnection via the using block, then the adoConnection is not closed.
Hope this clarifies things a bit more. Your Telerik points have been updated
Do get back in case you need further assistance.
the Telerik team
Follow @OpenAccessORM Twitter channel to get first the latest updates on new releases, tips and tricks and sneak peeks at our product labs!