private static SqlConnection OpenSqlConnection(string connectionKey, string transactionKey, string isolationLevelKey = null) { var connection = SqlConnection(connectionKey); if (connection.State != ConnectionState.Open) { try { connection.Open(); } catch (NullReferenceException exc) { throw new Exception("OpenConnectionException", exc); } catch (InvalidOperationException exc) { throw new Exception("OpenConnectionException", exc); } var isolationLevel = SqlIsolationLevel(isolationLevelKey); var transaction = connection.BeginTransaction(isolationLevel); WebCallContext.SetData(transactionKey, transaction); } return(connection); }
public SqlConnectionContext(SqlConnectionType connectiontype, SqlIsolationLevel sqlIsolationLevel) { lock (LockObject) { if (WebCallContext.GetData(ConnectionKey) == null) { WebCallContext.SetData(ConnectionKey, new SqlConnection(ConnectionString)); WebCallContext.SetData(IsolationLevelKey, sqlIsolationLevel); } else { throw new Exception("There is already a sql connection"); } } }