Data Access has been discontinued. Please refer to this page for more information.

Disposing the OpenAccessContext

This article is relevant to entity models that utilize the deprecated Visual Studio integration of Telerik Data Access. The current documentation of the Data Access framework is available here.

The OpenAccessContext.Dispose method releases the resources used by the context. This method closes the connection if it was opened by Telerik Data Access. After the Dispose method is called, operations that require an open connection, such as executing a query will cause an exception.

using (EntitiesModel dbContext = new EntitiesModel())
{
}
Using dbContext As New EntitiesModel()
End Using

Additionally, the context exposes the DisposeDatabase method. This method is used to dispose the underlying database object from one context, but applies to all the contexts using it. The "reason" argument is used for logging (if the logging is enabled).

EntitiesModel dbContext = new EntitiesModel();
dbContext.DisposeDatabase("ApplicationShutDown");
Dim dbContext As New EntitiesModel()
dbContext.DisposeDatabase("ApplicationShutDown")