Yan*_*nik 5 c# mongodb mongodb-.net-driver
在使用新部署的启用身份验证的 MongoDB 容器设置新环境时,我遇到了以下异常:"An unhandled exception has occurred while executing the request. MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---> System.NotSupportedException: Unable to create an authenticator."
就我而言,我使用的连接字符串如下例所示:mongodb://USER:PASSWORD@HOST:27017/?authMechanism=DEFAULT。该字符串在 MongoDB Compass 中工作得很好,但在我的 .NET 6.0 应用程序中却不行。
Yan*_*nik 19
如果您查看MongoCredential.cs#L469中 C#\xc2\xa0MongoDB 驱动程序的源代码,您会发现在检查身份验证机制时抛出此异常。
\n在连接字符串中指定确切的身份验证机制后,所有异常都消失了!
\n例子:mongodb://USER:PASSWORD@HOST:27017/?authMechanism=SCRAM-SHA-256
希望其他人在谷歌搜索时会发现我的答案有帮助!
\n快乐编码。
\n| 归档时间: |
|
| 查看次数: |
4677 次 |
| 最近记录: |