c# - SQLite & C# ] 如何控制编辑数据库文件的人数?

标签 c# algorithm sqlite synchronization

我现在正在使用 SQLite 编写一个简单的客户信息管理软件。

一个exe文件,一个db文件,一些dll文件。 - 就是这样:)

2~4 个人可能会同时运行这个 exe 文件并访问数据库。

他们不仅会阅读,还会经常编辑。

是的,现在来了最著名的问题之一......“同步”

每当有人尝试时,我都试图创建/删除一个临时的空文件 编辑它。 (这是访问数据库的“ key ”。)

但是一定有更好的方法:(

防止此问题的最佳方法是什么?

最佳答案

嗯,SQLite 已经为每次使用锁定了数据库文件,想法是多个应用程序可以共享同一个数据库。

但是,SQLite 的文档明确警告在网络上使用它:

SQLite will work over a network filesystem, but because of the latency associated with most network filesystems, performance will not be great. Also, the file locking logic of many network filesystems implementation contains bugs (on both Unix and Windows). If file locking does not work like it should, it might be possible for two or more client programs to modify the same part of the same database at the same time, resulting in database corruption. Because this problem results from bugs in the underlying filesystem implementation, there is nothing SQLite can do to prevent it.

A good rule of thumb is that you should avoid using SQLite in situations where the same database will be accessed simultaneously from many computers over a network filesystem.

因此假设您的“2-4 人”在不同的计算机上使用网络文件共享,我建议您不要使用 SQLite。请改用传统的客户端/服务器 RDBMS,它设计用于来自多个主机的多个并发连接。

您的应用程序仍然需要考虑并发问题(除非它推测性地获取用户当前正在查看的任何内容的锁,这通常是一个令人讨厌的想法)但至少您不必处理网络文件系统锁定问题还有

关于c# - SQLite & C# ] 如何控制编辑数据库文件的人数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3463455/

相关文章:

android - Sugar ORM 没有这样的表异常

c# - 多选 WinForms 列表框的双向绑定(bind)?

c# - 如何判断对象是否为值类型

arrays - 在未排序的数组中查找中位数(仅限于使用在线性中查找季度元素的子例程)

python - 创建一个有限制的排列

java - 循环播种的排序算法

android - 向 Toast 显示查询

java - 如何在 webapp 中寻找内存泄漏?

c# - 在多个 Cereal 之间分配繁重的工作(Microsoft Orleans)

c# - ASP.NET EnumDropDownListFor 生成 DropDown 但不选择模型的值