1

I've started using the MongoDB .Net driver to connect a WPF application to a MongoDB database hosted on MongoLabs.

But the following method I created to load the connection(called on the MainViewModel's constructor), threw a timeout exception on the line marked in the method below.

I tried to resolve the error further by adding an exception check of type MongoException to no avail. Also checked that the connection string is valid as per the docs and it seems so: (password starred out for security)

    private const string connectionString = "mongodb://<brianVarley>:<********>@ds048878.mongolab.com:48878/orders";

The specific error thrown is as follows:

An exception of type 'System.TimeoutException' occurred in mscorlib.dll

Complete Error Link: http://hastebin.com/funanodufa.tex

Does anyone know the reason why I'm getting the timeout on my connection method?

        public List<Customer> LoadCustomers()
        {
            var client = new MongoClient(connectionString);
            var database = client.GetDatabase("orders");
            //Get a handle on the customers collection:
            var collection = database.GetCollection<Customer>("customers");

            try
            {
                //Timeout error thrown at this line: 
                customers = collection.Find(new BsonDocument()).ToListAsync().GetAwaiter().GetResult();
            }
            catch(MongoException ex)
            {
                //Log exception here:
                MessageBox.Show("A handled exception just occurred: " + ex.Message, "Connection Exception", MessageBoxButton.OK, MessageBoxImage.Warning);          
            }

            return customers;
        } 
4
  • Have you tried connecting via mongo shell or some other method to determine if it's a server issue and not your code? Commented Nov 13, 2015 at 19:10
  • Nope, good suggestion actually, will give that a go now Commented Nov 13, 2015 at 19:11
  • I think your credentials for mongolab are invalid. I had the same issue a few weeks ago. Have you created a user for the database or are you maybe using the credentials for your mongolab account? Commented Nov 13, 2015 at 21:51
  • ok my connection string was incorrect, left these in < > . Will post an answer for anyone else with same issue. Commented Nov 14, 2015 at 1:55

1 Answer 1

1

Solved this error by re-editing my connection string. I had left these two symbols in my connection string in error, '<' and '>' between the user name and password credentials.

Correct format:

"mongodb://brianVarley:[email protected]:54118/orders";

Incorrect format:

"mongodb://<brianVarley>:<password;>@ds054118.mongolab.com:54118/orders";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.