mongodb - Unable to connect to MongoDB Atlas Cluster with MongoDB.Driver: 无法连接,因为目标机器主动拒绝
问题描述
我正在尝试从我的 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 地址列入白名单,但没有帮助。我的司机:
<PackageReference Include="MongoDB.Driver" Version="2.11.1" />
<PackageReference Include="MongoDB.Driver.Core" Version="2.11.1" />
我添加了 .Core 驱动程序试图解决这个问题,但它也没有帮助。我做错了什么?
PS虽然我可以连接mongo shell。
解决方案
No connection could be made because the target machine actively refused it.
不是白名单问题。
连接被拒绝表示远程 IP 的机器收到了数据包,但指定端口上没有进程监听。
远程 IP 在错误中报告为<my_ip>:53
. 端口 53 是 DNS 解析器的注册端口。. 因此,如果您在 上作为 DNS 服务器运行<my_ip>
,您需要弄清楚它为什么不监听。
如果没有在 上运行 DNS 服务器my_ip
,您需要弄清楚为什么您的 asp.net 将<my_ip>
其用作其 DNS 解析器。
您也可以尝试mongodb://
为您的集群使用旧 URL,以查看问题是否仅与 SRV 和 TXT 分辨率有关。
推荐阅读
- elasticsearch - 自动化弹性搜索快照和恢复的最佳方法是什么
- node.js - Express 路由器和路由 Node.js
- android - Dagger2 Multibinding [dagger.android.AndroidInjector.inject(T)] 找到一个依赖循环:
- c# - 如何在 Visual Studio 中从 2 个解决方案中调试多个 API
- spring - 没有关系和数学运算的 Spring JPA 连接表
- python - 当服务器运行长lua脚本时使redis客户端等待
- python - python - 数据框制作代表向量的列
- amazon-web-services - 如何通过目标 Ip 和端口号将 Socket 测试与 aws ec2 连接
- laravel - 无法从自定义开发域读取 cookie
- r - R闪亮的代码来获取从ui输入的输出