How to check if mongoDB connection is successful in C#
<p>I want to check if my connection to mongoDB is successful? I have tried this code but it is not totally working (it is working just in the case of successful connection)</p>

<pre><code>var client = new MongoClient("mongodb://name:pwd@ds***.mlab.com:port/db");
var db = client.GetDatabase("db");
var coll = db.GetCollection&lt;Book&gt;("book");

var server = client.GetServer();
server.Connect();


if(server.State.ToString() == "Connected")
{
            //do something
}
else
{
            //do something
}
</code></pre>

<p>EDIT:
I wanna do something like :</p>

<p><code>if(server.isConnected){ 
    form2.show();} 
 else {
    console.write("error");}</code> </p>