Click here to Skip to main content
15,883,705 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
my application host server is 192.168.248.142 and my mongodb server is 192.168.248.150,
and now the mongodb server was started. the message was below:
VB
------------------------------------------------------------------------------------
[root@mongodb ~]# mongod --port 27017 --bind_ip 192.168.248.150
2014-10-26T16:30:01.018+0800 [initandlisten] MongoDB starting : pid=3315 port=27017 dbpath=/data/db 64-bit host=mongodb.localdomain
2014-10-26T16:30:01.018+0800 [initandlisten] db version v2.6.4
2014-10-26T16:30:01.018+0800 [initandlisten] git version: 3a830be0eb92d772aa855ebb711ac91d658ee910
2014-10-26T16:30:01.018+0800 [initandlisten] build info: Linux build7.nj1.10gen.cc 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
2014-10-26T16:30:01.019+0800 [initandlisten] allocator: tcmalloc
2014-10-26T16:30:01.019+0800 [initandlisten] options: { net: { bindIp: "192.168.248.150", port: 27017 } }
2014-10-26T16:30:01.060+0800 [initandlisten] journal dir=/data/db/journal
2014-10-26T16:30:01.060+0800 [initandlisten] recover : no journal files present, no recovery needed
2014-10-26T16:30:01.586+0800 [initandlisten] waiting for connections on port 27017
--------------------------------------------------------------------------------------




in the c# project ,the core code is below:

C#
try
           {
               MongoDBClassOperation mdco = new MongoDBClassOperation();
               mdco.mongoConnectionHost = "192.168.248.150";
               mdco.dbname = "tutorial";
               mdco.collectionName = "weather";
               var _weather = mdco.GetCollection(mdco.dbname, mdco.mongoConnectionHost, mdco.collectionName);
               _weather.Insert(weather);
               this.txtTime.Text = this.txtTime.Text + "successfully";
           }
           catch (Exception ex)
           {
               this.txtException.Text = ex.ToString();
           }



-----

and attach the class MongoDBClassOperation is below:

XML
----------------------------------------------------------------------
public class MongoDBClassOperation
    {
        public string mongoConnectionHost;
        public string dbname;
        public string collectionName;
        public MongoServer CreateConnection(string mongoConnectionHost)
        {
            return MongoServer.Create("mongodb://" + mongoConnectionHost+":27017");
        }
        public MongoDatabase GetDatabase(string dbname,string mongoConnectionHost)
        {
            return this.CreateConnection(mongoConnectionHost).GetDatabase(dbname);
        }
        public MongoCollection<MongoCollectionClass.Info> GetCollection(string dbname,string mongoConnectionHost,string collectionName)
        {
            return this.GetDatabase(dbname, mongoConnectionHost).GetCollection<MongoCollectionClass.Info>(collectionName); ;
        }
    }
---------------------------------------------------------------------



and Finally still got the exception message populated below:



C#
MongoDB.Driver.MongoConnectionException: Unable to connect to server 192.168.248.150:27017: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 192.168.248.150:27017. ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 192.168.248.150:27017
   at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
   at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)
   at System.Net.Sockets.TcpClient.Connect(IPEndPoint remoteEP)
   at MongoDB.Driver.Internal.MongoConnection.Open()
   at MongoDB.Driver.Internal.MongoConnection.SendMessage(BsonBuffer buffer, Int32 requestId)
   at MongoDB.Driver.Internal.MongoConnection.SendMessage(MongoRequestMessage message)
   at MongoDB.Driver.Operations.CommandOperation`1.Execute(MongoConnection connection)
   at MongoDB.Driver.MongoServerInstance.Ping(MongoConnection connection)
   at MongoDB.Driver.MongoServerInstance.Connect()
   at MongoDB.Driver.Internal.DirectMongoServerProxy.Connect(TimeSpan timeout, ReadPreference readPreference)
   --- End of inner exception stack trace ---
   at MongoDB.Driver.Internal.DirectMongoServerProxy.Connect(TimeSpan timeout, ReadPreference readPreference)
   at MongoDB.Driver.Internal.DirectMongoServerProxy.ChooseServerInstance(ReadPreference readPreference)
   at MongoDB.Driver.MongoServer.AcquireConnection(ReadPreference readPreference)
   at MongoDB.Driver.MongoCollection.InsertBatch(Type nominalType, IEnumerable documents, MongoInsertOptions options)
   at MongoDB.Driver.MongoCollection.Insert(Type nominalType, Object document, MongoInsertOptions options)
   at GetWether.start.btnGetWether_Click(Object sender, EventArgs e) in c:\Users\scottvm\Documents\Visual Studio 2013\Projects\GetWether\GetWether\start.aspx.cs:line 89




-----------------------------------------


Anybody encountered those error before ,who can give me some help to fix the error? thanks a lot.
Posted
Updated 27-Oct-14 6:01am
v2
Comments
Mehdi Gholam 26-Oct-14 5:13am    
Check your firewall settings.
Kornfeld Eliyahu Peter 26-Oct-14 10:05am    
It seams your code failed on the socket connection...Check if the mongoDB port is opened on the firewall (possibly not)...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900