Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 16th, 2012  |  syntax: None  |  size: 1.99 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Using custom logger class to log errors and events slows down the process
  2. public class Logger
  3. {
  4.     public static void Log(string message)
  5.     {
  6.         mySqlClassInDAL.ExecuteNonQuery(string.Format("Insert into LogTable (msg) values ({0})",message));
  7.     }
  8. }
  9.        
  10. try
  11. {
  12.     PlayGame("Angry Pigs");
  13. }
  14. catch
  15. {
  16.     Logger.Log("Can't Play Game");
  17. }
  18.        
  19. public int ExecuteNonQuery(string NonQuery)
  20. {
  21.     using (SqlConnection sc = new SqlConnection(AppConnectionString))
  22.     {
  23.         SqlCommand sqlCommand = new SqlCommand(NonQuery, sc);
  24.         sqlCommand.Connection.Open();
  25.         return sqlCommand.ExecuteNonQuery();
  26.     }
  27. }
  28.        
  29. Audit Login -- network protocol: TCP/IP
  30. RPC:Completed   exec sp_executesql N'INSERT INTO ...
  31. Audit Logout
  32. RPC:Completed   exec sp_reset_connection
  33. Audit Login -- network protocol: TCP/IP
  34. RPC:Completed   exec sp_executesql N'INSERT INTO ...
  35. Audit Logout
  36. RPC:Completed   exec sp_reset_connection
  37.        
  38. Console.WriteLine(DateTime.Now);
  39. for (int i = 0; i < 1000; i++)
  40. {
  41.     ExecuteNonQuery(string.Format("INSERT INTO LogTable ... ", (i+baseNo).ToString()));
  42.     ExecuteNonQuery("UPDATE Customers... Where ID = " + (i+baseNo).ToString());
  43. }
  44. Console.WriteLine(DateTime.Now);
  45. .
  46. .
  47. .
  48. for (int i = 0; i < 1000; i++)
  49. {
  50.     List<object> parameterValues = new List<object> { "abc", 1, (i+baseNo).ToString() };
  51.     ExecuteSP("INSERTINTOLOG", parameterValues);
  52.     ExecuteSP("UPDATECustomers", new List<object> { i+baseNo });
  53. }
  54.  
  55. Console.WriteLine(DateTime.Now);
  56. .
  57. .
  58. .
  59.        
  60. var blockingCollection = new BlockingCollection<LogWriter>();
  61.        
  62. CREATE PROC sp_AddtoLog @in_values nText AS
  63.  
  64.  
  65.  
  66. DECLARE @hDoc int
  67.  
  68. --Prepare input values as an XML documnet
  69.  
  70. exec sp_xml_preparedocument @hDoc OUTPUT, @in_values
  71.  
  72. --Select data from the table based on values in XML
  73.  
  74. Insert into Log values (LogiD,Message)
  75.  
  76. SELECT * FROM Orders WHERE CustomerID IN (
  77.       SELECT LogID,Message FROM OPENXML (@hdoc, '/NewDataSet/Logs', 1)
  78.       WITH (LogID NCHAR(5),Message varchar(200)))
  79.  
  80. EXEC sp_xml_removedocument @hDoc
  81.        
  82. string logs =dsLog.GetXml();