无法使用 MongoDB.Driver 连接到 MongoDB Atlas 集群:无法建立连接,因为目标机器主动拒绝它

Unable to connect to MongoDB Atlas Cluster with MongoDB.Driver: No connection could be made because the target machine actively refused it

我正在尝试从我的 ASP.NET Core 3.1 应用程序连接到 MongoDB Atlas:

var client = new MongoClient("mongodb+srv://<user>:<password>@<my_db_instance>/test?retryWrites=true&w=majority");
var database = client.GetDatabase("test");

我收到以下错误:

ExtendedSocketException: No connection could be made because the target machine actively refused it. <my_ip>:53
System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)

DnsResponseException: Query 22151 => <my_db_instance> IN TXT on <my_ip>:53 failed with an error.
DnsClient.LookupClient.ResolveQuery(IReadOnlyList<NameServer> servers, DnsQuerySettings settings, DnsMessageHandler handler, DnsRequestMessage request, LookupClientAudit audit)

我曾尝试将 Atlas 中的所有 IP 地址列入白名单,但没有用。 我的 drivers:

<PackageReference Include="MongoDB.Driver" Version="2.11.1" />
<PackageReference Include="MongoDB.Driver.Core" Version="2.11.1" />

我添加了 .Core driver 试图解决这个问题,但没有帮助 also.What 我做错了吗?

P.S。不过,我可以连接 mongo shell。

No connection could be made because the target machine actively refused it.不是白名单问题

连接被拒绝表示远程IP的机器收到了数据包,但是没有进程在指定的端口上监听。

错误中报告的远程 IP 为 <my_ip>:53。端口 53 是 DNS 解析器的注册端口。 . 因此,如果您 运行 作为 <my_ip> 上的 DNS 服务器,您需要弄清楚为什么它没有监听。

如果 不是 运行 my_ip 上的 DNS 服务器,您需要弄清楚为什么 asp.net 使用 [=12] =] 作为其 DNS 解析器。

您也可以尝试使用旧的 mongodb:// url 集群来查看问题是否仅与 SRV 和 TXT 解析有关。