Can't connect UWP app to MongoDB

Roy Li - MSFT 33,451 Reputation points Microsoft Vendor
2019-12-12T08:17:16.487+00:00

I'm developing a UWP app using C# and the MongoDB connection works perfectly in the development computer. When I tried to export and install it in a different desktop it did not work.

I have some peculiarities on the target computer: no internet and no Visual Studio. I export my app, using the "Create App Packages" on Visual Studio, install all dependencies in the target desktop, and install the App.

Everything works, but the MongoDB Connection. When it tries to connect to the MongoDB Serve (local installation on target computer), it can't connect and I receive a timeout error.

What I know so far:

  • Nothing is wrong with the MongoDB installation, I can connect to it from the Mongo Compass and from a working 'App' from a different computer.
  • When I downloaded the Remote Debug Tools from Visual Studio, I got a message "installing missing libraries", and it started working (I had to get a new windows installation to reproduce the problem, without remote debugging).
  • I already tried to install the missing NuGet packages (MongoDB.Driver, MongoDB.Bson and MongoDB.Driver.Core) on the target computer, but it did not seem to change anything. Firewall is disabled.
  • All permissions were added to the UWP app.
  • Tried to connect without the loopback, but also did not work

Target windows version: 1809

MongoDB Packages version: 2.9.3

Visual Studio: 17

_client = new MongoClient(connectString);  
_db = _client.GetDatabase(database);  
  
BsonDocument doc = _instance._db.RunCommand((Command)"{ping:1}");  
IsConnected = doc["ok"] == 1;  
Logger.Log("[MONGO] Connected to MongoDB");  

Error message: "A timeout occured after 30000ms selecting a server using CompositeServerSelector...."

Universal Windows Platform (UWP)
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Roy Li - MSFT 33,451 Reputation points Microsoft Vendor
    2019-12-12T08:18:45.053+00:00

    Hello!

    Welcome to Microsoft Q&A!

    Could you please tell me if you are using localhost as the path?

    From this post Connecting to Database Services Like SQLServer/MySQL/MongoDB in UWP, there is another thing that needs to be noted, you need to enable Internet (Client & Server), Internet (Client) and Private Networks (Client & Server) capabilities in your manifest.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.