/// <summary> /// 지정 Query 실행 /// </summary> /// <param name="query">Query</param> /// <param name="type">Query의 실행 타입 (SELECT/NOSELECT)</param> /// <returns>함수 실행 결과 (DbmsResult 객체)</returns> public CommonStruct.DbmsResult Execute(string query, CommonEnum.ExecuteType type) { CommonStruct.DbmsResult result = new CommonStruct.DbmsResult(); SqlCommand mssqlCommand = null; SqlDataReader mssqlReader = null; DataTable resultTable = null; stopWatch.Start(); try { if (dbState != System.Data.ConnectionState.Open) { Connect(); } resultTable = new DataTable(); mssqlCommand = new SqlCommand(); mssqlCommand.Connection = mssqlConn; mssqlCommand.CommandType = System.Data.CommandType.Text; mssqlCommand.CommandText = query; mssqlCommand.CommandTimeout = 10; if (type == CommonEnum.ExecuteType.SELECT) { mssqlReader = mssqlCommand.ExecuteReader(); resultTable.Load(mssqlReader); } else { resultTable = null; mssqlCommand.ExecuteNonQuery(); } //LogHandler.WriteLog(string.Empty, string.Format("{0} :: Execute(Query = {1}) Success :: Type = {2} RowCount = {3}", this.ToString(), query, type, executeRows)); result.funcResult.isSuccess = true; result.funcResult.funcException = null; result.resultTable = resultTable; } catch (Exception ex) { //LogHandler.WriteLog(string.Empty, string.Format("{0} :: Execute(Query = {1}) Exception :: Message = {2}", this.ToString(), query, ex.Message)); result.funcResult.isSuccess = false; result.funcResult.funcException = ex; result.resultTable = null; } finally { if (mssqlCommand != null) { mssqlCommand.Dispose(); mssqlCommand = null; } } stopWatch.Stop(); result.funcResult.totalMilliseconds = stopWatch.ElapsedMilliseconds; stopWatch.Reset(); return(result); }
/// <summary> /// 지정 Procedure 실행 /// </summary> /// <param name="procName">Procedure</param> /// <param name="param">Procedure Parameter</param> /// <param name="type">Procedure의 실행 타입 (ExecuteType 변수)</param> /// <returns>함수 실행 결과 (DbmsResult 객체)</returns> public CommonStruct.DbmsResult Execute(string procName, Dictionary <string, object> param, CommonEnum.ExecuteType type) { CommonStruct.DbmsResult result = new CommonStruct.DbmsResult(); SqlCommand mssqlCommand = null; SqlDataReader mssqlReader = null; DataTable resultTable = null; stopWatch.Start(); try { if (dbState != System.Data.ConnectionState.Open) { Connect(); } resultTable = new DataTable(); mssqlCommand = new SqlCommand(); mssqlCommand.Connection = mssqlConn; mssqlCommand.CommandType = System.Data.CommandType.StoredProcedure; mssqlCommand.CommandText = procName; mssqlCommand.CommandTimeout = 10; foreach (KeyValuePair <string, object> p in param) { mssqlCommand.Parameters.AddWithValue(p.Key, p.Value.ToString()); } if (type == CommonEnum.ExecuteType.SELECT) { mssqlReader = mssqlCommand.ExecuteReader(); resultTable.Load(mssqlReader); } else { resultTable = null; mssqlCommand.ExecuteNonQuery(); } //LogHandler.WriteLog(string.Empty, string.Format("{0} :: Execute(ProcName = {1}) Success :: Type = {2} RowCount = {3}", this.ToString(), procName, type, executeRows)); result.funcResult.isSuccess = true; result.funcResult.funcException = null; result.resultTable = resultTable; } catch (Exception ex) { //LogHandler.WriteLog(string.Empty, string.Format("{0} :: Execute(ProcName = {1}) Exception :: Message = {2}", this.ToString(), procName, ex.Message)); result.funcResult.isSuccess = false; result.funcResult.funcException = ex; result.resultTable = null; } finally { if (mssqlCommand != null) { mssqlCommand.Dispose(); mssqlCommand = null; } } stopWatch.Stop(); result.funcResult.totalMilliseconds = stopWatch.ElapsedMilliseconds; stopWatch.Reset(); return(result); }