Is it possible to use a SQLite database in a shared folder in a PC?

醉酒当歌 提交于 2019-12-07 09:44:37

问题


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.


回答1:


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




回答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.




回答3:


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.




回答4:


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


来源:https://stackoverflow.com/questions/34705637/is-it-possible-to-use-a-sqlite-database-in-a-shared-folder-in-a-pc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!