6

I am developing an UWP application (Windows phone 10) and I have a SQLite database in a shared folder in a PC in my LAN. I would like to know if I can use this database in the windows phone app, like I do with my WPF application, that I can set the path of the database and I can use it from any computer in my lan.

Thanks.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Álvaro García
  • 18,114
  • 30
  • 102
  • 193

5 Answers5

5

Real Path:

\\192.168.1.102\Database\MyDB.db3

USE THIS Connection String:

Data Source='//192.168.1.102/Database/MyDB.db3';Version=3
  • cnStr.Replace("\", "/") in windows
Haddad
  • 301
  • 3
  • 5
2

As much I remember, it is not recommended by the developer, since file locking is very restricted in such settings (using networked file systems).

From the FAQ:

You should avoid putting SQLite database files on NFS if multiple processes might try to access the file at the same time. On Windows, Microsoft's documentation says that locking may not work under FAT filesystems if you are not running the Share.exe daemon. People who have a lot of experience with Windows tell me that file locking of network files is very buggy and is not dependable. If what they say is true, sharing an SQLite database between two or more Windows machines might cause unexpected problems.

But, if you intend to use it only from one process at a time (no concurrency involved) it should be fine.

Juergen
  • 12,378
  • 7
  • 39
  • 55
  • 1
    Yes, really it will access one process at the same time. I would like to try that for two reasons, for learning and because sometimes it is easier for me connect by phone than by computer. Could you shared and example how to do it? Thank you so much. – Álvaro García Jan 10 '16 at 17:25
2

Short answer:
Yes you can however you will need to be careful about the journaling mode you choose for example WAL does not work over a network file system.

Long answer:
If you see yourself in a situation where many clients/programs need to access a common database over a network you should consider a client/server database or provide an API of some sort that would sequentially persist the client's data to the SQLite DB.

For more info see Appropriate Uses of SQLite

  • Really I am testing the use of Sqlite in WP10, and the unique user I will be myself, so there is no problems of concurrency. – Álvaro García Jan 10 '16 at 13:08
  • Could you know a documentation where explains how could I connect from my mobile to a database that there is in \\MyPC\MyFolder\database.db? – Álvaro García Jan 10 '16 at 13:11
  • UWP is heavily sandboxed, and note the comment on http://ef.readthedocs.org/en/latest/getting-started/uwp.html that "When the application runs, databaseFilePath will always be under ApplicationData.Current.LocalFolder.Path. " – Rowland Shaw Jan 12 '16 at 16:35
  • 1
    The problem with the answer of "get a client/server database" is that this is often just impossible. I coded a great small application for a local task at work. My supervisor was all aboard, but IT said no, we couldn't have a database, even though the company runs SQL server. There were endless layers of red tape to get a database approved, so I told my supervisor I could just use an Access database and put it on our shared drive. It worked fine. – RobertSF Apr 24 '22 at 18:15
2

You can't just arbitrarily open a file from a UWP app, you need to use the RuntimeBroker to handle it, and the only mechanism that can talk to RuntimeBroker is the StorageFile API, which in turn knows nothing of shared folders in a LAN environment.

To access a shared database (SQLite or otherwise), your best option is to host it on some form of server, and build an API to interface to it (be it SOAP, REST, etc). You could still use a local cache on each client for disconnected usage, but you would need to handle the replication yourself.

Rowland Shaw
  • 37,700
  • 14
  • 97
  • 166
-1

cnStr.Replace("\", "/") in windows

This works great!

Bob
  • 11
  • 1
  • Could you elaborate a bit what the intention is here? – Mouse On Mars Dec 08 '20 at 19:42
  • My problem was addressing the db on another computer on the network. By simply doing the replacement suggested by Haddad, I reversed an incomprensible error. – Bob Dec 09 '20 at 11:55