Knight Data Access Layer
Open Close Wrapper
Basic Tasks C# > Patterns > Open Close Wrapper

To ensure the connection is closed after a set of operations, use the OpenCloseWrapper.

 

//New up the provider for what database we will be interacting with

SqLiteProvider provider = new SqLiteProvider();

 

//Build the connection string

SQLiteConnectionStringBuilder builder = new SQLiteConnectionStringBuilder();

builder.DataSource = _databaseFilePath;

provider.ConnectionString = builder.ConnectionString;

 

DataHelper db = new DataHelper(provider); //This is trial mode

//DataHelper db = new DataHelper(provider,"User Name", "License Key"); //This is the user name and license key on the receipt

 

//Log to the console

db.EnableLogging();

 

//Open the connection

using (new OpenCloseWrapper(db))

{

Console.WriteLine("Perform some database operation here");

} //Connection closed during dispose