IDbHelper dbHelper = new SqlHelper(connectionString); dbHelper.Open(); // open the connection // execute some queries dbHelper.Close(); // close the connection
using(var dbHelper = new OracleHelper(connectionString)) { dbHelper.Open(); // execute some queries } // connection will be automatically closed due to using statementIn this example, IDbHelper interface is implemented by OracleHelper class. The connection is opened using the connection string. After the queries are executed, the using block will dispose of the object and automatically call the Close method to close the connection. Package Library: There are various libraries available for implementing IDbHelper interface and using the Close method. Some popular libraries are System.Data.SqlClient for SqlHelper, Oracle.DataAccess.Client for OracleHelper, MySql.Data.MySqlClient for MySqlConnection, etc.