0

I want to connect my asp.net web app.to Amazone EC2 windows based machine there i installed mongodb. I tryed this :

MongoServerSettings settings = new MongoServerSettings();
settings.Server = new MongoServerAddress("localhost", 27017);
MongoServer server = new MongoServer(settings);
var database = server.GetDatabase("MessageDB");

and this:

MongoServerSettings settings = new MongoServerSettings();
settings.Server = new MongoServerAddress("ec2-XXXXXXXXX.eu-central-1.compute.amazonaws.com", 27017);
MongoServer server = new MongoServer(settings);
var database = server.GetDatabase("MessageDB");

and this:

var credential = MongoCredential.CreateMongoCRCredential("test", "user1", "password1");

var settings = new MongoClientSettings
{
    Credentials = new[] { credential }
};

var mongoClient = new MongoClient(settings);

timeout error?

1 Answer 1

1

First and foremost, please check if you the mongod service running

The first example is trying to connect to MongoDB which is running in local the same instance where the IIS or ASP.net application is running.

Check the following places

  1. If the mongod / service is running
  2. Try turning off the Windows Firewall
  3. Add the Security Group Rule [ AWS EC2 ] - All Traffic only to its own Security Group - Like All Traffic sg-12345e

In the Second, your trying to connect to mongodb which is running a different EC2 instance [or may the same machine].

Check the following places

  1. If the mongod / service is running
  2. Try turning off the Windows Firewall
  3. Security Group is allowing the private IP address of the ASP.net Application's EC2 instance via. the port 27017
  4. Check if the mongodb would allow remote connection [ http://www.mkyong.com/mongodb/mongodb-allow-remote-access ]
Sign up to request clarification or add additional context in comments.

3 Comments

i am not using localdb it is just a sample for showing my connection string types. there i have tryed your suggestions 1. is ok mongod service is running state 2. yes off state firewalls on windows server 2012 3. yes security grup is allowing all ip addressses like this : 0.0.0.0/0 but i couldnt see any document on your 4. step link thank you Naveen
i tryed Naveen but i have 2 problem 1. when i write this: bind_ip = 127.0.0.1,192.168.161.100,52.28.176.XXX to config file my service didnt restart. And the 2 is when i ping to the server public ip it hasn't reply me
I am not an expert in Mongo. But, I can comment on the Problem 2 : you need to open ICMP in Security Group from your IP to enable PING.

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.