Пример #1
0
        protected override void InternalOpen()
        {
            // Connect to the Catalog Store
            _connection = Session.Device.Store.GetSQLConnection();
            _connection.BeginTransaction(SQLIsolationLevel.ReadUncommitted);

            // Create a command using DevicePlanNode.Statement
            _command = _connection.CreateCommand(true);
            _command.CursorLocation  = SQLCursorLocation.Server;
            _command.CommandBehavior = SQLCommandBehavior.Default;
            _command.CommandType     = SQLCommandType.Statement;
            _command.LockType        = SQLLockType.ReadOnly;
            _command.Statement       = _devicePlanNode.Statement.ToString();

            // Set the parameter values
            foreach (CatalogPlanParameter planParameter in _devicePlanNode.PlanParameters)
            {
                _command.Parameters.Add(planParameter.SQLParameter);
                planParameter.SQLParameter.Value = GetSQLValue(planParameter.PlanNode.DataType, planParameter.PlanNode.Execute(Program));
            }

            // Open a cursor from the command
            _cursor = _command.Open(SQLCursorType.Dynamic, SQLIsolationLevel.ReadUncommitted);

            _bOF = true;
            _eOF = !_cursor.Next();
        }
Пример #2
0
 public void BeginTransaction()
 {
     try
     {
         if (SQLConnection != null)
         {
             SQLTransaction = SQLConnection.BeginTransaction();
         }
     }
     catch (Exception ex)
     {
         throw new DataAccessException("Unable to begin transaction.", ex);
     }
 }
Пример #3
0
        protected void EnsureOperators(ServerProcess process)
        {
            // no access
            var deviceSession = (SQLDeviceSession)Connect(process, process.ServerSession.SessionInfo);

            try
            {
                SQLConnection connection = deviceSession.Connection;
                if (!connection.InTransaction)
                {
                    connection.BeginTransaction(SQLIsolationLevel.Serializable);
                }
                try
                {
                    using (SQLCommand command = connection.CreateCommand(false))
                    {
                        using (Stream stream = GetType().Assembly.GetManifestResourceStream("SystemCatalog.sql"))
                        {
                            if (stream != null)
                            {
                                var systemCatalog = new StreamReader(stream).ReadToEnd();
                                if (systemCatalog.Length > 0)
                                {
                                    var batches = SQLUtility.ProcessBatches(systemCatalog, @"\");
                                    foreach (string batch in batches)
                                    {
                                        command.Statement = batch;
                                        command.Execute();
                                    }
                                }
                            }
                        }
                    }
                    connection.CommitTransaction();
                }
                catch
                {
                    connection.RollbackTransaction();
                    throw;
                }
            }
            finally
            {
                Disconnect(deviceSession);
            }
        }
        protected virtual int ExecuteSqlCommandNonQuery(string sqlCommand, CommandType type)
        {
            int affectedRows = 0;

            try
            {
                m_Logger.DebugFormat("__{0}__: {1}: SQL Command = {2}: ", this.GetType().Name, MethodInfo.GetCurrentMethod().Name, sqlCommand);
                SqlTransaction transaction = SQLConnection.BeginTransaction();
                affectedRows = ExecuteNonQuery(sqlCommand, type, transaction);
                transaction.Dispose();
            }
            catch (Exception ex)
            {
                m_Logger.ErrorFormat("__{0}__: {1}: SQL Exception={2}", this.GetType().Name, MethodInfo.GetCurrentMethod().Name, ex.ToString());
                throw;
            }
            return(affectedRows);
        }
Пример #5
0
 protected virtual void InternalBeginTransaction(SQLIsolationLevel isolationLevel)
 {
     _connection.BeginTransaction(isolationLevel);
 }