【发布时间】:2021-06-01 07:39:01
【问题描述】:
我正在使用 .Net Core 3.1 和 Hangfire MongoDb 进行后台调度,现在启动时它正在抛出
Autofac.Core.DependencyResolutionException: An exception was thrown while activating λ:Hangfire.IGlobalConfiguration.
---> MongoDB.Driver.MongoAuthenticationException: Unable to authenticate using sasl protocol mechanism SCRAM-SHA-1.
---> MongoDB.Driver.MongoCommandException: Command saslStart failed: Authentication failed..
at MongoDB.Driver.Core.WireProtocol.CommandUsingQueryMessageWireProtocol`1.ProcessReply(ConnectionId connectionId, ReplyMessage`1 reply)
at MongoDB.Driver.Core.WireProtocol.CommandUsingQueryMessageWireProtocol`1.Execute(IConnection connection, CancellationToken cancellationToken)
at MongoDB.Driver.Core.Authentication.SaslAuthenticator.Authenticate(IConnection connection, ConnectionDescription description, CancellationToken cancellationToken
我的配置文件中的连接字符串是正确的,我可以通过 Mongo 客户端从相同的连接字符串连接到数据库
"ConnectionStrings": {
"MongoJobSchedulerConnection": "mongodb://user:password@ipaddress:port/DbName"
}
这就是我在 Startup.cs 中添加 Hangfire 的方式
var mongoUrlBuilder = new MongoUrlBuilder(configuration.GetConnectionString("MongoJobSchedulerConnection"));
var mongoClient = new MongoClient(mongoUrlBuilder.ToMongoUrl());
services.AddHangfire((sp,configuration) => configuration
.SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
.UseSimpleAssemblyNameTypeSerializer()
.UseRecommendedSerializerSettings()
.UseActivator<JobActivator>(new SchedulerJobActivator(sp.GetRequiredService<IServiceScopeFactory>()))
.UseMongoStorage(mongoClient, mongoUrlBuilder.DatabaseName, new MongoStorageOptions
{
MigrationOptions = new MongoMigrationOptions
{
MigrationStrategy = new MigrateMongoMigrationStrategy(),
BackupStrategy = new CollectionMongoBackupStrategy()
},
Prefix = "SchedulerQueue",
CheckConnection = true
})
);
任何关于这个问题的提示都会有很大的帮助
谢谢
【问题讨论】:
-
您使用的是哪个版本的 MongoDB C# 驱动程序?你的 MongoDB 是什么版本?
-
@jawad MongoDb.Driver=2.10.3 和 MongoDb=4.2.4
标签: mongodb .net-core hangfire