How do I check to see if my ConnectionSting to MongoDb is open? (ASP.Net C#)

I just want see if my connection is open to my Mongo db

I'm lost.  This is what I have:
try
        {
             MongoServer.Create(ConfigurationManager.AppSettings["connectionstring"]);

            {

                server.Connect();
                return true;
                lbR.Text = "Open";
            }
        }
        catch
        {
            return false;
            lbR.Text = "Not Open";
        }

Open in new window

bmanmike39Asked:
Who is Participating?
 
bmanmike39Author Commented:
This is what I was looking for.  Thanks for the help.

I just could not figure out how to connect.

var mongo = new Mongo(Convert.ToString(ConfigurationManager.ConnectionStrings["connectionString"]));
            mongo.Connect();

            var db = mongo.GetDatabase("MProfile");
            var collection = db.GetCollection<Profile>("Profiles");
            return collection;

Open in new window

0
 
arnoldCommented:
Not first hand, but usually, the connection is assigned to a variable/place holders. Then as long as the variable is defined, the connection still valid opr can be used to test that the connection is still open.
Testing whether server is still define which in most cases probes, if the connection is still present the test is true if the connection closed, the test comes back as false.

You are using server.copnnect but you never assign the mangoserver.create to server.
I think line 3 above should be preceded by server=Mongoserver.......
0
 
anarki_jimbelCommented:
0
Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

 
bmanmike39Author Commented:
This is not what i was looking for. I was look im lost in the process.  Not finding any clear or working examples
0
 
anarki_jimbelCommented:
Try to clarify your problem and explain what you need to do.
0
 
bmanmike39Author Commented:
Still working on this, think I have my answer.  I will post if this is what I was looking for. please be patience.
0
 
bmanmike39Author Commented:
I figured it out myself.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.