Home > database >  Advice on how to use c # driven by SSL connection Mongo
Advice on how to use c # driven by SSL connection Mongo

Time:09-24

The building Lord white without SSL before, most recently with the huawei cloud, their database default SSL, gave it to a ca. CRT certificate, now want to use c # mongo Driver (2.7.0) to connect, see along while documents, has written the following code, but the connection is not on, for a great god how should change? Mongo version 3.4

 
Var cert=new X509Certificate2 (file.readallbytes (" ca. CRT) ", "password");//the password is the database password, so use?
Var Settings=new MongoClientSettings
{
Server=new MongoServerAddress (" X.X.X.X ", 8635),
The Credential=MongoCredential. CreateCredential (" mydatabase ", "rwuser", "password"),
SslSettings=new SslSettings
{
ClientCertificates=new [] {cert},
},
UseSsl=true
};
MongoClient client=new MongoClient (Settings);
IMongoDatabase db=client. GetDatabase (" mydatabase ");
Try
{
Var collection=db. GetCollection (" Admin ");
Var doc=collection. The Find (s=& gt; S.U sername=="admin"). FirstOrDefault ();//the program card in this step is not gone
Console. WriteLine (doc. Username);
}
The catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
  • Related