I have a class for establishing connection to sql server. now i want to connect my application with 3 connections respective of user accessing my application. how i can implement this with this class.
namespace SafetyNet.Logic
{
public class DBManager : IDisposable
{
#region Privates
public const string Database_Index = "";
private String _innerTransName = "innerTransaction";
private SqlConnection _conn = null;
private SqlTransaction _trans = null;
private bool _disposed = false;
public static readonly string DBConnectionString = ConfigurationManager.ConnectionStrings["Connection String"].ToString();
public DBManager()
: this(DBConnectionString)
{
string connection = "";
this._innerTransName = "Guide" + DateTime.UtcNow.Ticks.ToString();
}
public DBManager(string connectionString)
{
string connection = "";
_conn = new SqlConnection(connectionString);
this._innerTransName = "Guide" + DateTime.UtcNow.Ticks.ToString();
}
public String ConnectionString
{
get
{
return ConnectionString;
}
}
private void Open()
{
if (_conn != null && _conn.State != ConnectionState.Open)
{
_conn.Open();
}
}
public void Close()
{
if (_conn != null)
{
if (_conn.State == ConnectionState.Open)
_conn.Close();
}
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected void Finalize()
{
Dispose(true);
}
private void Dispose(bool disposing)
{
if (!_disposed)
{
if (_trans != null)
{
_trans.Dispose();
_trans = null;
}
if (_conn != null)
{
_conn.Close();
_conn.Dispose();
_conn = null;
}
_disposed = true;
}
}
#endregion
#region Transaction
public SqlTransaction BeginTransaction()
{
Open();
if (_trans == null)
_trans = _conn.BeginTransaction(IsolationLevel.ReadUncommitted, _innerTransName);
return _trans;
}
public void CommitTransaction()
{
if ((_conn.State == ConnectionState.Open) && (_trans != null))
{
_trans.Commit();
}
}
public void RollbackTransaction()
{
if ((_conn.State == ConnectionState.Open) && (_trans != null))
{
_trans.Rollback(_innerTransName);
}
}
public SqlConnection GetConnection()
{
return _conn;
}
#endregion
}
}
Thanks in advance.