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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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_jimbelSenior DeveloperCommented:
0
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
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

anarki_jimbelSenior DeveloperCommented:
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:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bmanmike39Author Commented:
I figured it out myself.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.