2013-09-28 38 views
1

我有一臺Mongodb 64位安裝的遠程服務器,並且運行mongod。我正在測試從家裏連接它。使用下面的連接字符串C#:Mongodb中的服務器連接

connectionString = "mongodb://Administrator:[email protected]: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 

我需要有我的服務器上的配置?或者在我的連接字符串?

+0

嘗試ping此端口上該服務器。也許你應該解鎖服務器安全端口。 mongodb在localhost中運行? –

+0

@NorbertPisz mongodb的默認允許本地主機連接正確嗎?如果是的話,如何在遠程服務器上配置我的mongodb以允許非常地連接?感謝隊友,我其實是這些東西的新寵。 –

+1

我實際上能夠在我的服務器本地建立連接,但使用另一臺機器連接到此服務器失敗了連接。 –

回答

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) 
}); 
0

我已經通過結合

bind_ip = 0.0.0.0