Пример #1
0
        public void ExecuteNonQuery <CONNECTION_TYPE, COMMAND_TYPE, ADAPTER_TYPE>(string connectionString, string commandText, string commandStyle)
            where CONNECTION_TYPE : DbConnection, new()
            where COMMAND_TYPE : DbCommand
            where ADAPTER_TYPE : DbDataAdapter, new()
        {
            try
            {
                if (new EncryptionFeatureToggle().FeatureEnabled)
                {
                    connectionString = AESGCM.SimpleDecrypt(connectionString, Convert.FromBase64String(ConfigurationManager.AppSettings["SchedulerEncryptionKey"]));
                }
            }
            catch (Exception ex)
            {
                Logger.Warn("ConfigurationError executing SqlJob job.", ex);
            }

            using (var dbControl = new DbControl <CONNECTION_TYPE, COMMAND_TYPE, ADAPTER_TYPE>(connectionString))
            {
                DbCommand command = (null != commandStyle && commandStyle.ToLower() == "storedprocedure")
                    ? dbControl.GetStoredProcedureCommand(commandText)
                    : dbControl.GetSqlStringCommand(commandText);

                try
                {
                    dbControl.ExecuteNonQuery(command);
                }
                catch (Exception ex)
                {
                    Logger.Error(string.Format("Error in SqlJob ({0}): ", _jobName), ex);
                    throw new JobExecutionException(ex.Message, ex, false);
                }
            }
        }
Пример #2
0
        public void ExecuteNonQuery <CONNECTION_TYPE, COMMAND_TYPE, ADAPTER_TYPE>(string connectionString, string commandText, string commandStyle)
            where CONNECTION_TYPE : DbConnection, new()
            where COMMAND_TYPE : DbCommand
            where ADAPTER_TYPE : DbDataAdapter, new()
        {
            using (var dbControl = new DbControl <CONNECTION_TYPE, COMMAND_TYPE, ADAPTER_TYPE>(connectionString))
            {
                DbCommand command = (null != commandStyle && commandStyle.ToLower() == "storedprocedure")
                    ? dbControl.GetStoredProcedureCommand(commandText)
                    : dbControl.GetSqlStringCommand(commandText);

                try
                {
                    dbControl.ExecuteNonQuery(command);
                }
                catch (Exception ex)
                {
                    Logger.Error("Error executing non-query.", ex);
                    throw new JobExecutionException("Error in SqlJob: " + ex.Message, ex, false);
                }
            }
        }