46 lines
1022 B
C#
46 lines
1022 B
C#
using System;
|
|
using System.Configuration;
|
|
using System.Data.SqlClient;
|
|
|
|
namespace LevelCode.License.DataAccess
|
|
{
|
|
public class DbConexao : IDisposable
|
|
{
|
|
private readonly SqlConnection _conexao;
|
|
|
|
public SqlConnection Conexao
|
|
{
|
|
get { return _conexao; }
|
|
}
|
|
|
|
public DbConexao()
|
|
{
|
|
string connectionString = ConfigurationManager
|
|
.ConnectionStrings["SQL"].ConnectionString;
|
|
|
|
_conexao = new SqlConnection(connectionString);
|
|
}
|
|
|
|
public void Abrir()
|
|
{
|
|
if (_conexao.State != System.Data.ConnectionState.Open)
|
|
_conexao.Open();
|
|
}
|
|
|
|
public void Fechar()
|
|
{
|
|
if (_conexao.State != System.Data.ConnectionState.Closed)
|
|
_conexao.Close();
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
if (_conexao != null)
|
|
{
|
|
Fechar();
|
|
_conexao.Dispose();
|
|
}
|
|
}
|
|
}
|
|
}
|