C# Mongodb中的服务器连接
我安装了一个64位Mongodb的远程服务器,并让mongod运行。我正在测试从家里连接它。使用以下连接字符串C:C# Mongodb中的服务器连接,c#,mongodb,C#,Mongodb,我安装了一个64位Mongodb的远程服务器,并让mongod运行。我正在测试从家里连接它。使用以下连接字符串C: connectionString = "mongodb://Administrator:mypassword@x.x.x.x:27017" 连接失败,出现以下错误: Unable to connect to server x.x.x.x:27017: A connection attempt failed because the connected party did not p
connectionString = "mongodb://Administrator:mypassword@x.x.x.x:27017"
连接失败,出现以下错误:
Unable to connect to server x.x.x.x: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 x.x.x.x:27017
我需要在服务器上进行配置吗?或者在我的连接字符串中?我通过绑定解决了这个问题
bind_ip = 0.0.0.0
我也无法使用connectionstring连接到远程MongoDB。我让它工作的方式有点冗长,但假设你试着这么做
var client = new MongoClient(connectionString);
那么这就可以起作用了:
var client = new MongoClient(
new MongoClientSettings
{
Credentials = new[]
{
MongoCredential.CreateCredential("Databasename","Administrator", "mypassword")
},
Server = new MongoServerAddress("x.x.x.x", 27017)
});
尝试在此端口上ping此服务器。也许您应该在服务器安全中解锁端口。mongodb在localhost中工作?@NorbertPisz mongodb的默认允许localhost连接,对吗?如果是这样的话,如何在远程服务器中配置我的mongodb以允许非本地连接?谢谢你,伙计,我对这些事情其实是新手。我实际上能够在我的服务器上建立本地连接,但使用另一台机器连接到此服务器失败。可能尝试配置端口。像这样@Wao你能找到解决方案吗?