we are trying to connect from Data Factory (ADF) to an Azure Cosmos DB with MongoDB Api. The DB is hosted by a third party which has granted access to a specific IP-Address range. Therefore, we are using a self hosted integration runtime. We've set up the Self Hosted IR and are using it with the linked service in ADF. We are using the linked service type "(Azure Cosmos DB (MongoDB API)" and trying to connect to a connection string in the following format: 'mongodb://<account-name>:<password>@<account-name>.mongo.cosmos.azure.com:10255/?ssl=true&replicaSet=globaldb&retrywrites=false&maxIdleTimeMS=120000&appName=<account-name>'. When we are trying to connect to the DB, we are receiving the following error:

"EndPoint: "Unspecified/s<account-name>.mongo.cosmos.azure.com:10255", State: "Disconnected", Type: "Unknown", HeartbeatException: "MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult) at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)"

The mongo db version is 3.6.0 and we have successfully verified the connection string via a local client (Darwin, mongosh cli). We already tested different versions and format for the connection string. We still cant connect.

Does anyone have any clue?

Hi @ShaikMaheer-MSFT ,

thank you for your reply. Actually, I did include the @ signs in my connection string - I just removed them when posted my question here. I also tried version 3.2 format and it raised another error. However, version 3.6+ format is expected to work since I used the exact same connection string locally with mongosh cli and it worked.

I also encountered the bug that the connection string was changed from ?ssl=true to ?tsl=true which was mentioned here: https://learn.microsoft.com/en-us/answers/questions/63537/problem-with-cosmos-db-mongo-db-connection.html . Changing this still didn't do the trick.

Do you have any other ideas? Already spend a good amount of time troubleshooting.

Thanks and BR
Steffen

Hi @Steffen Klempau ,

Thank you for posting ask in Microsoft Q&A Platform.

Below are some observations. Could you please correct them and try.

For 3.2 server version, the string pattern is mongodb://<cosmosdb-name>:<password>@<cosmosdb-name>.documents.azure.com:10255/?ssl=true&replicaSet=globaldb

For 3.6+ server versions, the string pattern is mongodb://<cosmosdb-name>:<password>@<cosmosdb-name>.mongo.cosmos.azure.com:10255/?ssl=true&replicaSet=globaldb&retrywrites=false&maxIdleTimeMS=120000&appName=@<cosmosdb-name>@

It seems in your case, you used 3.6+ version pattern. But @ Symbols missing for appName=@<cosmosdb-name>@ Kindly include them and try. If not, Still not works kindly feel free to try 3.2 version format as well.

Kindly cross check and make sure you have set "isServerVersionAbove32" value to true.

Please let us know how it goes. Please let us know if any further queries.

To determine where the issue is, I prepared a test tool with the core code of ADF cosmos mongo connector.
Please follow this:

  • Download and unzip the tool: https://guosen.blob.core.windows.net/share/cosmosmongo/TestMongoDbSDK.zip
  • Edit the "config.json" to specify the "connectionString" and "database"
  • Run "TestCurrentSDK.exe" on the SHIR machine, it will try to connect to the server
    If the tool can connect successfully, ADF should also work. Otherwise, there must be some network or configuration issues on the SHIR machine and cosmos mongo server.
  •