title: Simple SqlCommand - Very High CPU
body: <p>I made a simple Console Application. (Code below).</p>
  
  <p>When I run the program on my computer, it works fine. However, when I run it on our server (Windows Server 2008) which is a virtual machine, after a minute of so, the process takes all the CPU. It goes to 100% usage until I close the application.. The only difference I can think of would be that the database on my computer is local and on the server, the database used is on another machine..</p>
  
  <p>Any idea what could cause the CPU to go crazy...?</p>
  
  <pre><code>static void Usings()
  {
      using (SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]))
      {
          conn.Open();
          SqlCommand cmd = new SqlCommand("SELECT GETDATE()", conn);
          SqlDataReader dr = cmd.ExecuteReader();
  
          if (dr.Read())
              Console.WriteLine(dr[0].ToString());
  
          dr.Dispose();
          cmd.Dispose();
      }
  
      Console.ReadKey();
  }
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I modified the code to only open a SqlConnection and I still get the behaviour.</p>
  
  <p>I also added some code to get notified on the Garbage Collector Approach. The CPU goes to the top milliseconds before I receive the notification. So I suspect the garbage collector to be responsible for this. Any clue? Suggestion where I could dig deeper? </p>
  
  <p>New code:</p>
  
  <pre><code>    static void Main(string[] args)
      {
          #region Register for Garbage Collector Notifications
          GC.RegisterForFullGCNotification(10, 10);
  
          // Start a thread using WaitForFullGCProc.
          Thread thWaitForFullGC = new Thread(new ThreadStart(WaitForFullGCProc));
          thWaitForFullGC.Start();
          #endregion
  
          using (SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]))
          {
              conn.Open();
              using (SqlCommand cmd = new SqlCommand("SELECT GETDATE()", conn))
              { }
          }
  
          _sw.Start();
  
          Log("Waits for key press...");
          Console.Read();
      }
  </code></pre>
  
  <p>PS: If I do not open the SQL Connection, CPU stays stable (0%)....</p>
  
  <p>When the program starts...
  <a href="https://i.stack.imgur.com/3J4r2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3J4r2.png" alt="enter image description here"></a></p>
  
  <p>After exactly 3 minutes 11 seconds and some ms...</p>
  
  <p><a href="https://i.stack.imgur.com/s2IgR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/s2IgR.png" alt="enter image description here"></a></p>