Exemple #1
0
        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);
        }
Exemple #2
0
 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");
         }
     }
 }