- Create new database connection object using
using (var dbConnection = ConnectionFactory.CreateConnection(connectionString))
{
// database operations
}
OR
using (var dbConnection = ConnectionFactory.CreateConnection())
{
// database operations
}
- where connectionString is string object which has value of connectionstring for database, or it will take default connectionstring from web config. Name of the default connectionstring must be "DefaultConnection".
- dbConnection.ExecuteSingle(); // with/Without Mapper
- dbConnection.ExecuteList(); // with/Without Mapper
- dbConnection.ExecuteNonQuery();
- dbConnection.ExecuteScalar();
- dbConnection.ExecuteNonQueryWithScope(); // with return parameter
- dbConnection.ExecuteSingleProc(); // with/Without Mapper
- dbConnection.ExecuteListProc(); // with/Without Mapper
- dbConnection.ExecuteNonQueryProc();
- dbConnection.ExecuteScalarProc();
- dbConnection.ExecuteNonQueryProcWithReturn() // with return parameter, Name of the return parameter must be "ReturnValue"
- dbConnection.BeginTransaction();
- dbConnection.CommitTransaction();
- dbConnection.RollbackTransaction();
- dbConnection.GetConnectionString();
- dbConnection.GetOutParameters();
- dbConnection.Dispose(); // dbConnection object will be automatically disposed as it inherits IDisposable.