コード例 #1
0
 private static string GetDbName(DbType t)
 {
     try
     {
         string    sql = "";
         DataTable dt  = new DataTable();
         if (t == DbType.Oracle)
         {
             Oracle oracle = GetOracleDbInstance();
             sql = "SELECT INSTANCE_NAME FROM v$instance";
             dt  = oracle.ExecSQLReturnDataTable(sql);
         }
         else
         {
             SQLServer sqlserver = GetSqlServerDbInstance();
             sql = "SELECT DB_NAME() AS DBName";
             dt  = sqlserver.ExecSQLReturnDataTable(sql);
         }
         if (dt.Rows.Count == 0)
         {
             return("");
         }
         else
         {
             return(dt.Rows[0][0].ToString());
         }
     }
     catch
     {
         return("");
     }
 }
コード例 #2
0
        //private static string SaveToDb(DbType t, string recordType, string program,
        //    string function, string error_message, string exception_trace, string param_value, bool saveScreenShot,string client)
        private static void SaveToDb(object p)
        {
            ParaClass pC = (ParaClass)p;

            string dbName     = TruncateString(GetDbName(pC.dbType), 50);
            string clientName = TruncateString(GetClientName(), 50);
            string ip         = TruncateString(GetLocalIP(), 50);

            try
            {
                string sql = "";
                byte[] b   = null;
                if (pC.saveScreenShot)
                {
                    b = GetScreenSnapShot();
                }

                if (pC.dbType == DbType.Oracle)
                {
                    Oracle oracle = GetOracleDbInstance();
                    //sql = "INSERT INTO LITEON.DNS_PROGRAM_EXEC_LOG(DB_NAME,RECORD_TYPE,PROGRAM_NAME,FUNCTION_NAME,ERROR_MESSAGE,"
                    //    + "EXCEPTION_TRACE,PARAM_VALUE,IP,CLIENT_NAME,SCREEN_SHOT,LOG_DATETIME) VALUES ("
                    //    + ":thisDbName,:thisRecordType,:thisProgName,:thisFuncName,:thisErrMsg,"
                    //    + ":thisExcept,:thisPara,:thisIP,:thisClient,:thisScreen,SYSDATE)";
                    sql = "LITEON.USP_SAVE_PROGRAM_LOG";
                    OracleParameter[] ops =
                    {
                        new OracleParameter("v_type",      OracleDbType.Varchar2, 0, pC.logType,         ParameterDirection.Input),
                        new OracleParameter("v_progName",  OracleDbType.Varchar2, 0, pC.program,         ParameterDirection.Input),
                        new OracleParameter("v_funcName",  OracleDbType.Varchar2, 0, pC.function,        ParameterDirection.Input),
                        new OracleParameter("v_errMsg",    OracleDbType.Varchar2, 0, pC.error_message,   ParameterDirection.Input),
                        new OracleParameter("v_exMsg",     OracleDbType.Varchar2, 0, pC.exception_trace, ParameterDirection.Input),
                        new OracleParameter("v_param",     OracleDbType.Varchar2, 0, pC.param_value,     ParameterDirection.Input),
                        new OracleParameter("v_IP",        OracleDbType.Varchar2, 0, ip,                 ParameterDirection.Input),
                        new OracleParameter("v_client",    OracleDbType.Varchar2, 0, clientName,         ParameterDirection.Input),
                        new OracleParameter("v_img",       OracleDbType.Blob,     0, b,                  ParameterDirection.Input),
                        new OracleParameter("v_startTime", OracleDbType.Varchar2, 0, pC.startTime,       ParameterDirection.Input)
                    };
                    oracle.ExecProcNonQuery(sql, ops);
                    //oracle.ExecSQLNonQuery2(sql, ops);
                }
                else if (pC.dbType == DbType.SqlServer)
                {
                    SQLServer sqlserver = GetSqlServerDbInstance();
                    //sql = "INSERT INTO DNS_PROGRAM_EXEC_LOG(DB_NAME,RECORD_TYPE,PROGRAM_NAME,FUNCTION_NAME,ERROR_MESSAGE,"
                    //    + "EXCEPTION_TRACE,PARAM_VALUE,IP,CLIENT_NAME,SCREEN_SHOT,LOG_DATETIME) VALUES ("
                    //    + "@dbName,@recordType,@program,@funcName,@errmsg,"
                    //    + "@except,@params,@ip,@client,@SnapShot,GETDATE())";
                    sql = "EXEC USP_SAVE_PROGRAM_LOG @type,@progName,@funcName,@errMsg,@exMsg,@param,@IP,@client,@img,@startTime";
                    SqlParameter[] paras = new SqlParameter[10];

                    paras[0]       = new SqlParameter("@type", SqlDbType.VarChar, 1);
                    paras[0].Value = pC.logType;
                    paras[1]       = new SqlParameter("@progName", SqlDbType.NVarChar, 50);
                    paras[1].Value = pC.program;
                    paras[2]       = new SqlParameter("@funcName", SqlDbType.NVarChar, 50);
                    paras[2].Value = pC.function;
                    paras[3]       = new SqlParameter("@errMsg", SqlDbType.NVarChar, 2000);
                    paras[3].Value = pC.error_message;
                    paras[4]       = new SqlParameter("@exMsg", SqlDbType.NVarChar, 2000);
                    paras[4].Value = pC.exception_trace;
                    paras[5]       = new SqlParameter("@param", SqlDbType.NVarChar, 2000);
                    paras[5].Value = pC.param_value;
                    paras[6]       = new SqlParameter("@IP", SqlDbType.NVarChar, 50);
                    paras[6].Value = ip;
                    paras[7]       = new SqlParameter("@client", SqlDbType.NVarChar, 50);
                    paras[7].Value = clientName;
                    paras[8]       = new SqlParameter("@img", SqlDbType.Image);
                    paras[9]       = new SqlParameter("@startTime", SqlDbType.VarChar, 20);
                    paras[9].Value = pC.startTime;
                    if (b == null)
                    {
                        paras[8].Value = DBNull.Value;
                    }
                    else
                    {
                        paras[8].Value = b;
                    }
                    sqlserver.ExecSQLNonQuery2(sql, paras);
                }
                else
                {
                }
                //return "OK";
            }
            catch//(Exception ex)
            {
                //return ex.Message;
            }
            finally
            {
                GC.Collect();
            }
        }