Example #1
0
        public static ConfigSection GetSection(string sectionName)
        {
            try
            {
                lock (_lock)
                {
                    if (!_sections.ContainsKey(sectionName))
                    {
                        ConfigSection section
                            = System.Configuration.ConfigurationManager.GetSection(sectionName) as ConfigSection;

                        // null이라도 일단 등록. 한번만 실제로 컨피그를 읽기 위함.
                        _sections.Add(sectionName, section);

                        if (section == null)
                        {
                            // 로그를 남기기 위해 예외 발생
                            throw new Exception(string.Format("{0} 섹션이 정의되지 않았습니다.", sectionName));
                        }
                    }
                }
                return(_sections[sectionName]);
            }
            catch (Exception ex)
            {
                LogManager.AddExceptionData(ref ex, "sectionName", sectionName);

                LogManager.WriteError(LogSourceType.ClassLibrary, ex);

                throw;
            }
            //$$소스분석에 의해 수정됨-끝.$$
        }
Example #2
0
        /// <summary>
        /// SELECT 수행.
        /// </summary>
        /// <param name="commandType">CommandType</param>
        /// <param name="commandText">SQL 혹은 프로시저명</param>
        /// <param name="pageIndex">페이지 인덱스 (0 base)</param>
        /// <param name="pageSize">페이지 당 Row 개수</param>
        /// <param name="parameters">SqlParameter 배열</param>
        /// <returns>데이터셋</returns>
        protected DataTable ExecuteQuery(CommandType commandType, string commandText, int pageIndex, int pageSize, params SqlParameter[] parameters)
        {
            try
            {
                DataTable dt = null;

                using (SqlCommand command = new SqlCommand())
                {
                    command.Connection  = this.Connection;
                    command.CommandType = commandType;
                    command.CommandText = commandText;

                    if (parameters != null)
                    {
                        foreach (SqlParameter p in parameters)
                        {
                            if (p != null)
                            {
                                if ((p.Direction == ParameterDirection.InputOutput || p.Direction == ParameterDirection.Input) &&
                                    (p.Value == null))
                                {
                                    p.Value = DBNull.Value;
                                }
                                command.Parameters.Add(p);
                            }
                        }
                    }

                    using (SqlDataAdapter da = new SqlDataAdapter(command))
                    {
                        dt = new DataTable();

                        if (pageSize == 0)
                        {
                            da.Fill(dt);
                        }
                        else
                        {
                            da.Fill((pageSize * pageIndex), pageSize, dt);
                        }
                    }
                }

                return(dt);
            }
            catch (Exception ex)
            {
                // 오류 데이터 추가
                LogManager.AddExceptionData(ref ex, "CommandText", commandText);
                foreach (SqlParameter p in parameters)
                {
                    LogManager.AddExceptionData(ref ex, p.ParameterName, p.Value);
                }

                // 오류 반환
                throw;
            }
        }
Example #3
0
        /// <summary>
        /// INSERT/UPDATE/DELETE 수행.
        /// </summary>
        /// <param name="commandType">CommandType</param>
        /// <param name="commandText">SQL 혹은 프로시저명</param>
        /// <param name="timeOut">타임아웃</param>
        /// <param name="parameters">SqlParameter 배열</param>
        /// <returns>영향 받은 Row 개수</returns>
        protected int ExecuteNonQuery(CommandType commandType, string commandText, int timeOut, params SqlParameter[] parameters)
        {
            try
            {
                using (SqlCommand command = new SqlCommand())
                {
                    command.Connection  = this.Connection;
                    command.CommandType = commandType;
                    command.CommandText = commandText;
                    if (timeOut > 0)
                    {
                        command.CommandTimeout = timeOut;
                    }

                    if (parameters != null)
                    {
                        foreach (SqlParameter p in parameters)
                        {
                            if (p != null)
                            {
                                if ((p.Direction == ParameterDirection.InputOutput || p.Direction == ParameterDirection.Input) &&
                                    (p.Value == null))
                                {
                                    p.Value = DBNull.Value;
                                }
                                command.Parameters.Add(p);
                            }
                        }
                    }

                    return(command.ExecuteNonQuery());
                }
            }
            catch (Exception ex)
            {
                // 오류 데이터 추가
                LogManager.AddExceptionData(ref ex, "CommandText", commandText);
                foreach (SqlParameter p in parameters)
                {
                    LogManager.AddExceptionData(ref ex, p.ParameterName, p.Value);
                }

                // 오류 반환
                throw;
            }
        }