예제 #1
0
        public static void Log(string LOG_LEVEL, string ERROR_MESSAGE, string SUBJECT, string MESSAGE, string UPDT_MESSAGE = "")
        {
            SQLSERVER DB = new SQLSERVER(logConnection);

            try
            {
                DB.Open();
                DB.ExecuteNonQuery(
                    "INSERT INTO SERVERLOG ( " +
                    "       [TIME_STAMP] " +
                    "       ,[LOG_LEVEL] " +
                    "       ,[PG_ID] " +
                    "       ,[ERROR_MESSAGE] " +
                    "       ,[SUBJECT] " +
                    "       ,[MESSAGE] " +
                    "       ,[UPDT_MESSAGE] " +
                    "       ,[UPDTDT] " +
                    "       ,[UPDTID] " +
                    "       ,[UPDTTRM] " +
                    "       ) " +
                    "VALUES ( " +
                    "       CONVERT(VARCHAR, GETDATE(), 120) " +
                    "       ," + LOG_LEVEL + " " +     //0:情報、1:エラー
                    "       ,'" + Path.GetFileName(Environment.GetCommandLineArgs()[0]).Replace(".vshost", "") + "' " +
                    "       , '" + ERROR_MESSAGE.Replace("'", "''") + "' " +
                    "       , '" + SUBJECT.Replace("'", "''") + "' " +
                    "       ,'" + MESSAGE.Replace("'", "''") + "' " +
                    "       ,'" + UPDT_MESSAGE.Replace("'", "''") + "' " +
                    "       ,CONVERT(VARCHAR, GETDATE(), 120) " +
                    "       ,'" + loginId + "' " +
                    "       ,'" + Dns.GetHostName() + "' " +
                    "       )");
            }
            catch (Exception ex)
            {
                File.AppendAllText("ErrorLog.txt", DateTime.Now.ToString("yyyy/MM/dd (dddd) hh時mm分ss秒") + " " + ex.Message + "      " + ex.StackTrace);
                MessageBox.Show("データベースに接続ができませんでした(" + Application.StartupPath + @"\ErrorLog.txt):" + ex.Message + Environment.NewLine + ex.StackTrace);
                throw;
            }
            finally
            {
                DB.Close();
            }
        }
예제 #2
0
        public static void Insert(string sql, string connection)
        {
            SQLSERVER DB = new SQLSERVER(connection);

            try
            {
                DB.Open();
                DB.ExecuteNonQuery(sql);
                SQLSERVERHelper.Log("0", "", "挿入", sql);
            }
            catch (Exception)
            {
                //SQLSERVERHelper.Log("1", ex.Message + Environment.NewLine + ex.StackTrace, errorTitle, sql, "NoLoginUser");
                //MessageBox.Show("エラー発生:" + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace);
                throw;
            }
            finally
            {
                DB.Close();
            }
        }