我正在尝试使用 c# 通过 ssl 证书连接到 MongoDB 服务器。我收到 System.TimeoutException (使用 CompositeServerSelector 选择服务器 30000 毫秒后发生超时)。
我开始通过 MongoClientSetting 对象进行连接。这是代码:
MongoClientSettings settings = new MongoClientSettings();
settings.MaxConnectionLifeTime = new TimeSpan(12, 0, 0);
settings.UseSsl = true;
settings.VerifySslCertificate = false;
var cert = new X509Certificate2("mongoDBCAFile.cer");
settings.SslSettings = new SslSettings{
ClientCertificates = new[] { cert }
};
settings.Servers = new[]{
new MongoServerAddress("xyz1.intranet.companyname.com", 12345),
new MongoServerAddress("xyz2.intranet.companyname.com", 12345)
};
settings.ReplicaSetName = "replicaName";
var cred = MongoCredential.CreateGssapiCredential("username@intranet.companyname.com").WithMechanismProperty("SERVICE_NAME", "servicename");
settings.Credential = cred;
var client = new MongoClient(settings);
var database = client.GetDatabase("DatabaseName");
var collection = database.GetCollection<BsonDocument>("CollectionName");
//This is the place of error
var count1 = collection.CountDocuments(new BsonDocument());
我尝试使用 ConnectTimeout、SocketTimeout 和 wTimeOut,但错误是一样的。
我也尝试使用此处提到的连接字符串做同样的事情,但我不知道如何使用这么多参数创建连接字符串。
慕妹3242003
相关分类