Database.EnsureConnectionOpen Method
Opens Connection (if it’s not open) and returns an IDisposable object you can use to close it (if it wasn’t open).
Namespace: DbExtensions
Assembly: DbExtensions.dll
Syntax
public IDisposable EnsureConnectionOpen()
Return Value
Type: IDisposable
An IDisposable object to close the connection.
Remarks
Use this method with the using
statement in C# or Visual Basic to ensure that a block of code is always executed with an open connection.
Examples
using (db.EnsureConnectionOpen()) {
// Execute commands.
}