C# 蒙哥达司机。通过SCRAM-SHA-1进行认证
我正在尝试与Azure Cosmos DB(MongoDb)建立连接。我使用MongoDb.Driver v2.8.1。有人能帮我吗?非常感谢C# 蒙哥达司机。通过SCRAM-SHA-1进行认证,c#,mongodb,asp.net-core,mongodb-.net-driver,C#,Mongodb,Asp.net Core,Mongodb .net Driver,我正在尝试与Azure Cosmos DB(MongoDb)建立连接。我使用MongoDb.Driver v2.8.1。有人能帮我吗?非常感谢 var configurationSection = _configuration.GetSection("MongoDb"); MongoUrl mongoUrl = new MongoUrl(configurationSection["connectionString"]); var d
var configurationSection = _configuration.GetSection("MongoDb");
MongoUrl mongoUrl = new MongoUrl(configurationSection["connectionString"]);
var databaseName = configurationSection["databaseName"];
var userName = mongoUrl.Username;
var password = mongoUrl.Password;
MongoClientSettings settings = new MongoClientSettings();
settings.Server = mongoUrl.Server;
settings.UseSsl = true;
settings.SslSettings = new SslSettings();
settings.SslSettings.EnabledSslProtocols = SslProtocols.Tls12;
settings.ConnectTimeout = TimeSpan.FromMinutes(1);
MongoIdentity identity = new MongoInternalIdentity(databaseName, userName);
MongoIdentityEvidence evidence = new PasswordEvidence(password);
settings.Credential = new MongoCredential("SCRAM-SHA-1", identity, evidence);
var mongoClient = new MongoClient(settings);
尝试从集合获取数据时引发以下异常:
An unhandled exception occurred while processing the request.
MongoCommandException: Command saslContinue failed: SaslFailed. ConnectionId e6e7c4d7-4dcc-40c5-ad56-3307f3323a1a ActivityId: 9af84117-0000-0000-0000-000000000000.
MongoDB.Driver.Core.WireProtocol.CommandUsingQueryMessageWireProtocol<TCommandResult>.ProcessReply(ConnectionId connectionId, ReplyMessage<RawBsonDocument> reply)
MongoAuthenticationException: Unable to authenticate using sasl protocol mechanism SCRAM-SHA-1.
MongoDB.Driver.Core.Connections.BinaryConnection.OpenHelperAsync(CancellationToken cancellationToken)
Stack Query Cookies Headers
MongoCommandException: Command saslContinue failed: SaslFailed. ConnectionId e6e7c4d7-4dcc-40c5-ad56-3307f3323a1a ActivityId: 9af84117-0000-0000-0000-000000000000.
MongoDB.Driver.Core.WireProtocol.CommandUsingQueryMessageWireProtocol<TCommandResult>.ProcessReply(ConnectionId connectionId, ReplyMessage<RawBsonDocument> reply)
MongoDB.Driver.Core.WireProtocol.CommandUsingQueryMessageWireProtocol<TCommandResult>.ExecuteAsync(IConnection connection, CancellationToken cancellationToken)
MongoDB.Driver.Core.Authentication.SaslAuthenticator.AuthenticateAsync(IConnection connection, ConnectionDescription description, CancellationToken cancellationToken)
Show raw exception details
MongoAuthenticationException: Unable to authenticate using sasl protocol mechanism SCRAM-SHA-1.
MongoDB.Driver.Core.Connections.BinaryConnection.OpenHelperAsync(CancellationToken cancellationToken)
MongoDB.Driver.Core.Servers.Server.GetChannelAsync(CancellationToken cancellationToken)
MongoDB.Driver.Core.Operations.FindOperation<TDocument>.ExecuteAsync(IReadBinding binding, CancellationToken cancellationToken)
MongoDB.Driver.OperationExecutor.ExecuteReadOperationAsync<TResult>(IReadBinding binding, IReadOperation<TResult> operation, CancellationToken cancellationToken)
MongoDB.Driver.MongoCollectionImpl<TDocument>.ExecuteReadOperationAsync<TResult>(IClientSessionHandle session, IReadOperation<TResult> operation, ReadPreference readPreference, CancellationToken cancellationToken)
MongoDB.Driver.MongoCollectionImpl<TDocument>.UsingImplicitSessionAsync<TResult>(Func<IClientSessionHandle, Task<TResult>> funcAsync, CancellationToken cancellationToken)
Babelfish.ME.MongoDb.Data.Services.AbstractDataService<TEntity>.FindAsync(BsonDocument filter, BsonDocument sort, int skip, int limit) in AbstractDataService.cs
处理请求时发生未处理的异常。
MongoCommand异常:命令saslContinue失败:SaslFailed。连接ID e6e7c4d7-4dcc-40c5-ad56-3307f3323a1a活动ID:9af84117-0000-0000-0000-0000000。
MongoDB.Driver.Core.WireProtocol.CommandUsingQueryMessageWireProtocol.ProcessReply(ConnectionId ConnectionId,ReplyMessage reply)
MongoAuthenticationException:无法使用sasl协议机制SCRAM-SHA-1进行身份验证。
MongoDB.Driver.Core.Connections.BinaryConnection.OpenHelperAsync(CancellationToken CancellationToken)
堆栈查询Cookies头
MongoCommand异常:命令saslContinue失败:SaslFailed。连接ID e6e7c4d7-4dcc-40c5-ad56-3307f3323a1a活动ID:9af84117-0000-0000-0000-0000000。
MongoDB.Driver.Core.WireProtocol.CommandUsingQueryMessageWireProtocol.ProcessReply(ConnectionId ConnectionId,ReplyMessage reply)
MongoDB.Driver.Core.WireProtocol.CommandUsingQueryMessageWireProtocol.ExecuteAsync(IConnection connection,CancellationToken CancellationToken)
MongoDB.Driver.Core.Authentication.SaslAuthenticator.authenticateSync(IConnection连接,ConnectionDescription描述,CancellationToken CancellationToken)
显示原始异常详细信息
MongoAuthenticationException:无法使用sasl协议机制SCRAM-SHA-1进行身份验证。
MongoDB.Driver.Core.Connections.BinaryConnection.OpenHelperAsync(CancellationToken CancellationToken)
MongoDB.Driver.Core.Servers.Server.GetChannelAsync(CancellationToken CancellationToken)
MongoDB.Driver.Core.Operations.FindOperation.ExecuteAsync(IReadBinding绑定,CancellationToken CancellationToken)
MongoDB.Driver.OperationExecutor.ExecuteReadOperationAsync(IReadBinding绑定、IReadOperation操作、CancellationToken CancellationToken)
MongoDB.Driver.MongoCollectionImpl.ExecuteReadOperationAsync(IClientSessionHandle会话、IReadOperation操作、ReadPreference ReadPreference、CancellationToken CancellationToken)
MongoDB.Driver.MongoCollectionImpl.UsingImplicitSessionAsync(Func-funcAsync,CancellationToken-CancellationToken)
AbstractDataService.cs中的Babelfish.ME.MongoDb.Data.Services.AbstractDataService.FindAsync(BsonDocument过滤器、BsonDocument排序、int skip、int limit)
我使用MongoClient设置连接到Azure CosmoDb
var mongoClientSettings = new MongoClientSettings()
{
Server = new MongoServerAddress(mongoConfig.Host, mongoConfig.Port),
Credential = MongoCredential.CreateCredential(mongoConfig.Database, mongoConfig.Username, mongoConfig.Password),
UseSsl = true,
ReplicaSetName = "globaldb"
};
var client = new MongoClient(mongoClientSettings);
显然,您会用自己的值替换配置部分
我能看到的唯一区别是,您没有指定
ReplicateSetName
,而且MongoCredential.CreateCredential
返回的身份验证类型是SCRAM-SHA-256类型,而您的类型是SCRAM-SHA-1非常感谢。这个问题在全球范围内得到了解决。出于成本考虑,我们公司决定使用自己的MongoDb服务器,而不是Azure Cosmos。以下代码适用于自己的服务器。开始时,我使用SCRAM-SHA-1
var configurationSection = _configuration.GetSection("MongoDb");
MongoUrl mongoUrl = new MongoUrl(configurationSection["connectionString"]);
var connectionString = configurationSection["connectionString"];
var mongoClient = new MongoClient(connectionString);
你能修改一下格式吗?