// 10 20 30 // 123456789012345678901234567890123456 // 61FFB6F0-AE23-4588-A673-BA6674A7EB17 public static void LogActivity(string pUserID, string pPageName, LogActivityCategory pCategory, string pEventName, long pTimeElapsed, string pDetails, DbTask pDbt) { StringBuilder sb = new StringBuilder(); sb.AppendLine("INSERT INTO [ActivityLog] ([UserID],[PageName],[Category],[EventName],[TimeElapsed],[Details],[ConnString]) "); sb.AppendLine("VALUES ("); sb.Append(DbUtility.DelimitText(pUserID) + ","); sb.Append(DbUtility.DelimitText(pPageName) + ","); sb.Append("'" + pCategory.ToString() + "',"); sb.Append("'" + pEventName + "',"); sb.Append(DbUtility.DelimitNonText(pTimeElapsed) + ","); sb.Append(DbUtility.DelimitText(pDetails) + ","); sb.Append(DbUtility.DelimitText(pDbt.ConnectionName)); sb.Append(")"); string queryString = sb.ToString(); var dbt = new DbTask("Aw_ActivityLog", queryString); dbt.DbTaskSummaryOn = false; DbWorker.ExecuteQuery(ref dbt, delegate(int pCount, Exception pExc) { if (pExc != null) { Debug.WriteLine("Error Writing ActivityLog"); Debug.WriteLine("Sql="); Debug.WriteLine(queryString); Debug.WriteLine(DBMaria.PrettyException(pExc)); } }); }
private static bool ConnectionNotOpenHappened(ref DbTask pDbt, MethodBase pMB) { if (pDbt.ConnectionWasSuccessful == true) { return(false); } if (pDbt.ConnectionWasSuccessful == false) { // TODO: ActivityLog entry Debug.WriteLine("Connection Did Not Open No Database Operation Attempted"); Debug.WriteLine(DBMaria.PrettyMethodBase(pMB)); Debug.WriteLine(DBMaria.PrettyException(pDbt.ConnectionFailedException)); return(true); } return(true); }
public static void DebugSql(DbTask pDbt) { //if (ConnectionNotOpenHappened(ref pDbt,MethodBase.GetCurrentMethod())) return; var DBDeets = new DbTaskSummary { QueryRaw = pDbt.Sql }; //if (pDbt.Sql.ToLower().IndexOf("insert into [activitylog]") > -1) return; if (pDbt.Sql != null & DbUtility.IsAdHocSql(pDbt.Sql)) { DBDeets.QueryType = TypeOfQuery.AdHocSQL; } if (DBDeets.QueryType == TypeOfQuery.AdHocSQL) { DBDeets.QueryRaw = pDbt.Sql; DBDeets.QueryPrettyFormatted = DBMaria.PrettySQL(pDbt.Sql); DBDeets.QueryAsExecutableText = DBDeets.QueryPrettyFormatted; } else { DBDeets.QueryType = TypeOfQuery.SProc; // TODO function in Utility StringBuilder sbSprocCall = new StringBuilder(); sbSprocCall.Append("EXEC " + pDbt.SqlCmd.CommandText + " "); foreach (SqlParameter parm in pDbt.SqlCmd.Parameters) { sbSprocCall.AppendFormat(" {0}={1}, ", parm.ParameterName, DbUtility.DelimitObject(parm.Value)); } string sprocCallExpanded = sbSprocCall.ToString(); // remove the trailing comma if (sprocCallExpanded.EndsWith(", ")) { sprocCallExpanded = sprocCallExpanded.Substring(0, sprocCallExpanded.Length - 2); } DBDeets.QueryPrettyFormatted = sprocCallExpanded; DBDeets.QueryAsExecutableText = DBDeets.QueryPrettyFormatted; } if (pDbt.IsSqlCommand) { DBDeets.QueryType = TypeOfQuery.CommandObject; DBDeets.QueryAsExecutableText = pDbt.SqlCmd.TSqlFromFromCommand(); } DBDeets.MthdBsPretty = DBMaria.PrettyMethodBase(pDbt.MethodBase); // timing transfer DBDeets.MilliSecondsElapsed = pDbt.SW.ElapsedMilliseconds; DBDeets.TimingPretty = DBMaria.PrettyDBtTiming(pDbt); if (pDbt.DbQueryType == DbQueryType.DataReader || pDbt.DbQueryType == DbQueryType.DataTable) { // TODO: may need tweaking with multiple result sets DBDeets.BlackBoxAsText = DBMaria.PrettyDataTable(pDbt.LogCaptureDataset.Tables[0], Schema: pDbt.Schema); DBDeets.BlackBox = pDbt.LogCaptureDataset; } DBDeets.RawExceptionQuery = pDbt.ExceptionQuery; DBDeets.RawExceptionDelegate = pDbt.ExceptionDelegate; DBDeets.ExceptionPretty = string.Empty; if (DBDeets.RawExceptionQuery != null) { DBDeets.ExceptionPretty = "QueryException=" + DBMaria.PrettyException(pDbt.ExceptionQuery); } if (DBDeets.RawExceptionDelegate != null) { DBDeets.ExceptionPretty += System.Environment.NewLine + "DelegateException=" + DBMaria.PrettyException(pDbt.ExceptionDelegate); } Debug.WriteLine(DBMaria.PrettyDBDeets(DBDeets)); }