Просто узнаете, как использовать драйвер MongoDB C # и задаетесь вопросом, почему «MongoClient» пытается постоянно переподключаться с неправильными учетными данными?
Как мне прекратить автоматическое подключение и работать с «MongoAuthenticationException», чтобы пользователь мог попробоватьвойти в систему?
namespace MongoDBConsole
{
internal class Program
{
public static void Main(string[] args)
{
MainAsyc().Wait();
Console.ReadLine();
}
static async Task MainAsyc()
{
var pw = "admin";
var sPwd = new SecureString();
foreach (var c in pw)
{
sPwd.AppendChar(c);
}
var settings = new MongoClientSettings()
{
Credential = MongoCredential.CreateCredential("admin", "admin", sPwd)
};
var client = new MongoClient(settings);
}
}
}
Монго лог
2018-10-06T02:33:00.354+1000 I NETWORK [conn3] received client metadata from 127.0.0.1:53063 conn3: { driver: { name: "mongo-csharp-driver", version: "2.7.0.0" }, os: { type: "Windows", name: "Microsoft Windows 10.0.17134", architecture: "x86_32", version: "10.0.17134" }, platform: ".NET Framework 4.7.3163.0" }
2018-10-06T02:33:00.409+1000 I ACCESS [conn3] SASL SCRAM-SHA-256 authentication failed for admin on admin from client 127.0.0.1:53063 ; AuthenticationFailed: SCRAM authentication failed, storedKey mismatch
2018-10-06T02:33:00.409+1000 I NETWORK [conn3] end connection 127.0.0.1:53063 (0 connections now open)
2018-10-06T02:33:00.410+1000 I NETWORK [listener] connection accepted from 127.0.0.1:53064 #4 (1 connection now open)
2018-10-06T02:33:00.410+1000 I NETWORK [conn4] received client metadata from 127.0.0.1:53064 conn4: { driver: { name: "mongo-csharp-driver", version: "2.7.0.0" }, os: { type: "Windows", name: "Microsoft Windows 10.0.17134", architecture: "x86_32", version: "10.0.17134" }, platform: ".NET Framework 4.7.3163.0" }
2018-10-06T02:33:00.468+1000 I ACCESS [conn4] SASL SCRAM-SHA-256 authentication failed for admin on admin from client 127.0.0.1:53064 ; AuthenticationFailed: SCRAM authentication failed, storedKey mismatch
2018-10-06T02:33:00.469+1000 I NETWORK [conn4] end connection 127.0.0.1:53064 (0 connections now open)