question

RoyLi-MSFT avatar image
0 Votes"
RoyLi-MSFT asked ·

Can't connect UWP app to MongoDB

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...."

uwp
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

RoyLi-MSFT avatar image
0 Votes"
RoyLi-MSFT answered ·

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.

· Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.