Question

Fire Lizard on Sun, 25 Sep 2016 12:35:02


I have following problem

While I am trying to connect to the DocumentDB database using MongoDb API:

var cstring = "mongodb://textadmin:<MY VERY SECRET PASSWORD>@<MY SERVER>.documents.azure.com:10250/?ssl=true"       

var client = new MongoDB.Driver.MongoClient(cstring)       

var server = client.GetServer()       

server.Ping()

I have the following error:

Authentication failed because the remote party has closed the transport stream

Any ideas what to change in the code (or in the server settings perhaps)?


Sponsored



Replies

sivethe on Mon, 03 Oct 2016 16:30:23


You need to set EnabledSslProtocols to TLS12 to be able to connect to DocumentDB using MongoDB API. By default, the Mongo C# driver does not use TLS1.2 causing the connection to fail during SSL handshake.

Sample Code:

MongoClientSettings settings = new MongoClientSettings();
settings.Server = new MongoServerAddress(host, 10250);
settings.UseSsl = true;
settings.SslSettings = new SslSettings();
settings.SslSettings.EnabledSslProtocols = SslProtocols.Tls12;

MongoIdentity identity = new MongoInternalIdentity(dbName, userName);
MongoIdentityEvidence evidence = new PasswordEvidence(password);

settings.Credentials = new List<MongoCredential>()
{
    new MongoCredential("SCRAM-SHA-1", identity, evidence)
};

MongoClient client = new MongoClient(settings);

Reference: https://azure.microsoft.com/en-us/documentation/articles/documentdb-mongodb-samples/