SocketException when trying to send data to mongoDB on Azure

夙愿已清 提交于 2020-05-18 01:44:28

问题


I have a mongodb replica set hosted in a VM wjth Windows Server 2012 R2 on the Azure platform, my problem is that when I'm trying to insert data from an external client using the C# driver or even consulting them from a GUI client (mongoVUE, robomongo ...) I often get the following exception which permanently locks the program (even trying a Server.reconnect() does not resolve).

No such host is known
Type: System.Net.Sockets.SocketException

Stack:    at System.Net.Dns.GetAddrInfo(String name)
   at System.Net.Dns.InternalGetHostByName(String hostName, Boolean includeIPv6)
   at System.Net.Dns.GetHostAddresses(String hostNameOrAddress)
   at MongoDB.Driver.MongoServerAddress.ToIPEndPoint(AddressFamily addressFamily)
   at MongoDB.Driver.MongoServerInstance.GetIPEndPoint()

I've tried setting:

MongoDefaults.SocketTimeout = TimeSpan.FromMinutes(5);
MongoDefaults.ConnectTimeout = TimeSpan.FromMinutes(5);
MongoDefaults.MaxConnectionIdleTime = TimeSpan.FromMinutes(5);

putting an hardcoded public IP address of the server in the connection string and testing it from different locations but it seems that something on the server blocking connections.

Has anyone any idea how I can fix it?


回答1:


I solved!The problem was that I started mongodb with a single replica set that's not configured correctly, removing the option --replset when starting mongod all works correctly.



来源:https://stackoverflow.com/questions/24405130/socketexception-when-trying-to-send-data-to-mongodb-on-azure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!