title: How to check connection to mongodb
body: <p>I use <code>MongoDB</code> drivers to connect to the database. When my form loads, I want to set up connection and to check whether it is ok or not. I do it like this:</p>
  
  <pre><code>var connectionString = "mongodb://localhost";
  var client = new MongoClient(connectionString);
  var server = client.GetServer();
  var database = server.GetDatabase("reestr");
  </code></pre>
  
  <p>But I do not know how to check connection. I tried to overlap this code with <code>try-catch</code>, but to no avail. Even if I make an incorrect connectionString, I still can not get any error message.</p>