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:
------------------------------------------------------------------------------------
[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:
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:
----------------------------------------------------------------------
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:
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.