コード例 #1
0
        public DBDataReader(string process, string sql, string connectionKey, Boolean singleRow, Boolean SingleValue)
        {
            var formattedSql = DBDataTable.FormatSql(sql);

            Log4Net.SqlStatementStack.Push(new Log4Net.SqlStatementStackMessage(formattedSql));
            Log4Net.LogDebug(formattedSql, connectionKey);

            Connection = StartUp.OpenConnection(connectionKey);

            DBCommand = new SqlCommand(formattedSql, Connection);
            DBCommand.CommandTimeout = StartUp.TimeOut;

            try
            {
                ReturnValue = DBCommand.ExecuteScalar();
            }
            catch
            {
                try
                {
                    if (Connection.State == ConnectionState.Closed)
                    {
                        Connection.Open();
                    }
                    ReturnValue = DBCommand.ExecuteScalar();
                }
                catch (Exception ex)
                {
                    LogException(sql, "Scalar", ex, process);
                }
            }

            LogInfo(sql, "Scalar");
        }
コード例 #2
0
        public DBDataReader(string process, string sql, string connectionKey, Boolean singleRow)
        {
            var formattedSql = DBDataTable.FormatSql(sql);

            Log4Net.SqlStatementStack.Push(new Log4Net.SqlStatementStackMessage(formattedSql));
            Log4Net.LogDebug(formattedSql, connectionKey);

            Connection = StartUp.OpenConnection(connectionKey);

            DBCommand = new SqlCommand(formattedSql, Connection);
            DBCommand.CommandTimeout = StartUp.TimeOut;
            ReturnValue = string.Empty;

            try
            {
                DBReader = DBCommand.ExecuteReader(CommandBehavior.SingleRow);

                DBReader.Read();

                for (var i = 0; i < DBReader.FieldCount; i++)
                {
                    ReturnValue += DBReader[i] + "|";
                }
            }
            catch
            {
                try
                {
                    if (Connection.State == ConnectionState.Closed)
                    {
                        Connection.Open();
                    }
                    DBReader = DBCommand.ExecuteReader(CommandBehavior.SingleRow);
                }
                catch (Exception ex)
                {
                    LogException(formattedSql, String.Empty, ex, process);
                }
            }
        }
コード例 #3
0
        public DBDataReader(string process, string sql, string connectionKey)
        {
            var formattedSql = DBDataTable.FormatSql(sql);

            try
            {
                Log4Net.SqlStatementStack.Push(new Log4Net.SqlStatementStackMessage(formattedSql));
                Log4Net.LogDebug(formattedSql, connectionKey);

                Connection = StartUp.OpenConnection(connectionKey);

                DBCommand = new SqlCommand(formattedSql, Connection);
                DBCommand.CommandTimeout = StartUp.TimeOut;

                DBReader = DBCommand.ExecuteReader(CommandBehavior.Default);
            }
            catch (Exception ex)
            {
                LogException(formattedSql, String.Empty, ex, process);
            }

            LogInfo(sql, "Reader");
        }
コード例 #4
0
        public void GetData(string sql, string connectionKey)
        {
            var formattedSql = DBDataTable.FormatSql(sql);

            Log4Net.SqlStatementStack.Push(new Log4Net.SqlStatementStackMessage(formattedSql));
            Log4Net.LogDebug(formattedSql, connectionKey);

            var connectionString = StartUp.GetConnectionString(connectionKey);

            using (var connection = new SqlConnection(connectionString))
            {
                var dataAdapter = new SqlDataAdapter(formattedSql, connection);

                dataAdapter.Fill(DBDataset);
                DBDataset.CaseSensitive = false;
            }

            LogResultCount(DBDataset);

            if (!sql.StartsWith("exec AuditDetailInsert") && !sql.StartsWith("exec AuditSummaryUpdate") && !sql.StartsWith("exec AuditSummaryInsert"))
            {
                DBDataReader.MessageLog("SQL: " + sql);
            }
        }