title: The type initializer for 'System.Transactions.Diagnostics.DiagnosticTrace' threw an exception
body: <p>I need help solving this error.<br><br>
  This is the error <code>{"The type initializer for 'System.Transactions.Diagnostics.DiagnosticTrace' threw an exception."}</code></p>
  
  <p><br>
  I am using Access database and Platform for build configuration is Any CPU.</p>
  
  <p>Sometimes the code runs well and sometimes it suddenly throws this exception. There are many similar questions asked here but none of them is solving my error.<br><br></p>
  
  <p>This is my connection string</p>
  
  <pre><code>DbPath = @"d:\Ek.mdb";
  ConnectionString =@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+DbPath+";User Id=admin;Password=;";
  </code></pre>
  
  <p>This is my function to open the connection<br>
  I am getting the error on <code>Con.Open()</code> </p>
  
  <pre><code>public bool OpenConnection()
          {
              if (Con == null)
              {
                  Con = new OleDbConnection(ConnectionString);
              }
              else if ((Con.State == ConnectionState.Broken || Con.State == ConnectionState.Closed) &amp;&amp; (Con.State!=ConnectionState.Open))
              {
                  Con.Open();
                  Tx = Con.BeginTransaction(IsolationLevel.ReadCommitted);
                  return true;
              }
              else if (IsConnectionBusy())
              {
                  throw new DataException("Connection Busy");
              }
              return false;
          }
  </code></pre>
  
  <p>This how I Close the connection after executing queries
  <br></p>
  
  <pre><code>public Boolean CloseConnection()
          {
              if(IsConnectionBusy())
                  throw new DataException("Connection Busy");
              if (Con.State==ConnectionState.Open)
              {
                  Tx.Commit();
                  Con.Close();
                  return true;
              }
              return false;
          }
  public bool IsConnectionBusy()
      {
          switch (Con.State)
          {
              case ConnectionState.Connecting:
              case ConnectionState.Executing:
              case ConnectionState.Fetching:
                  return true;
          }
          return false;
      }
  </code></pre>
  
  <p>I cannot find that why does it runs sometimes perfectly and then sometimes throws this exception. 
  <br>
  Any help will be greatly appreciated. I have tried too much for solving this error but couldn't.<br><br>
  What I have noticed is at this line.<br></p>
  
  <pre><code> else if ((Con.State == ConnectionState.Broken || Con.State == ConnectionState.Closed) &amp;&amp; (Con.State!=ConnectionState.Open))
  </code></pre>
  
  <p><br>
  The connection is in <code>closed state</code>. When it is executing the <code>Con.Open()</code> statement the <code>Connection</code> state changes to <code>Open</code> and after that this error is thrown.
  <br>
  Also while debugging the error is not caused. It is only caused when I don't put a <code>breakpoint</code> at that place.
  <br>
  At <code>Con.Open()</code> when I put a breakpoint and stop there for a few seconds only for the first time then there is no error thrown. After that if I disable the breakpoint and no error is thrown...!!!</p>