/// <summary> /// This functions creates the SqlCommand object that will be used to write to the DB /// </summary> private static SqlCommand GetTraceSqlCommand(string source, TraceEventType eventType, string message, string stackTrace) { SqlConnection connection = new SqlConnection(_connectionString); SqlCommand cmd = new SqlCommand("_RecordSystemError", connection); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandTimeout = 20; // set error cmd.AddVarChar("application", HttpRuntime.AppDomainAppVirtualPath ?? "Unknown", 150); cmd.AddVarChar("clientname", TDSSettings.GetClientName() ?? "Unknown", 100); // set message cmd.AddVarCharMax("msg", message); // set stacktrace cmd.AddVarCharMax("stackTrace", stackTrace); // get unique ID for the context of this request Guid id = (Trace.CorrelationManager.ActivityId == Guid.Empty) ? Guid.NewGuid() : Trace.CorrelationManager.ActivityId; cmd.AddUniqueIdentifier("ApplicationContextID", id); // create the process name string proc = eventType + ":" + source; // add HTTP information HttpRequest currentRequest = WebHelper.GetCurrentRequest(); if (currentRequest != null) { // add IP if (currentRequest.UserHostAddress != null) { // string clientIP = request.ServerVariables["REMOTE_ADDR"]; string clientIP = currentRequest.UserHostAddress; if (currentRequest.UserHostName != null && currentRequest.UserHostAddress != currentRequest.UserHostName) { clientIP += String.Format(" ({0})", currentRequest.UserHostName); } cmd.AddVarChar("clientIP", clientIP, 50); } // add http page to the proc name Uri url = currentRequest.Url; if (url != null & url.Segments.Length > 0) { proc += ":" + url.Segments[url.Segments.Length - 1]; } // add opportunity information if available if (TDSIdentity.Current != null) { long? testeeKey = TDSIdentity.Current.Values.Get <long?>("T_KEY"); string testKey = TDSIdentity.Current.Values.Get <string>("O_TKEY"); Guid? oppKey = TDSIdentity.Current.Values.Get <Guid?>("O_KEY"); cmd.AddBigInt("testee", testeeKey); cmd.AddVarChar("test", testKey, 150); cmd.AddUniqueIdentifier("testoppkey", oppKey); // cmd.AddInt("opportunity", tdsCookie.Get<int?>("O_NUM")); } } cmd.AddVarChar("proc", proc, 50); // add user information /*if (TDSIdentity.Current != null) * { * long testeeKey = TDSIdentity.Current.Values.Get<long>("k"); * string testID = TDSIdentity.Current.Values.Get("t"); * int opportunity = TDSIdentity.Current.Values.Get<int>("o"); * * cmd.AddBigInt("testee", testeeKey); * cmd.AddVarChar("test", testID, 150); * cmd.AddInt("opportunity", opportunity); * }*/ return(cmd); }