Example #1
0
		public void TraceIsReusable()
		{
			SqlConnection conn = new SqlConnection(Common.Properties.ConnectionString);
			SqlTrace trace = new SqlTrace(System.Environment.MachineName,conn);
			SqlCommand cmd = new SqlCommand("SELECT * FROM master..sysdatabases", conn);

			Assert.AreEqual(trace.TotalReads, 0);
			trace.Start();

			try
			{
				conn.Open();
				cmd.ExecuteNonQuery();
			}
			finally
			{
				conn.Close();
			}

			trace.Stop();


			Assert.AreNotEqual(trace.TotalReads, 0);
			trace.ClearData();
			Assert.AreEqual(trace.TotalReads, 0);
			trace.Start();

			try
			{
				conn.Open();
				cmd.ExecuteNonQuery();
			}
			finally
			{
				conn.Close();
			}

			trace.Stop();


			Assert.AreNotEqual(trace.TotalReads, 0);

		}
 public Entities()
     : base("name=Entities")
 {
     Database.Log = s => SqlTrace.WriteSQL(s);
 }
 private void OnSqlTrace(object sender, DbCommand command, string connectionString)
 {
     SqlTrace?.Invoke(sender, new DbTraceEventArgs(command, connectionString));
 }