database 简单的多用户数据库解决方案

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1856313/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 07:32:18  来源:igfitidea点击:

Simple multi-user database solution

databasesqlitefirebirdmulti-user

提问by Ben Mc

I've written a Windows desktop application that works with Sqlite very nicely. It was a single user app, and the database sits right on the machine where the app runs.

我编写了一个 Windows 桌面应用程序,可以很好地与 Sqlite 配合使用。这是一个单用户应用程序,数据库就位于应用程序运行的机器上。

However, the application has grown, and now multiple users should be able to run the app and connect to one shared database.

但是,该应用程序已经发展壮大,现在多个用户应该能够运行该应用程序并连接到一个共享数据库。

I'd like to just be able to share the sqlite file on a network drive, but that would obviously result in corrupted data unless someone has any ideas.

我只想能够在网络驱动器上共享 sqlite 文件,但这显然会导致数据损坏,除非有人有任何想法。

I guess I could require the install of a database server, but a commercial MySQL license doesn't make sense, PostgreSQL is different enough that I'd have to rewrite a lot of my application. I haven't worked with Firebird at all, so I'm not sure if that's a good solution or not.

我想我可能需要安装数据库服务器,但商业 MySQL 许可证没有意义,PostgreSQL 的不同之处足以让我不得不重写我的很多应用程序。我根本没有与 Firebird 合作过,所以我不确定这是否是一个好的解决方案。

Are there any Sqlite database servers that can be installed that handle the incoming transactions on the Sqlite database file?

是否可以安装任何 Sqlite 数据库服务器来处理 Sqlite 数据库文件上的传入事务?

If I require the client to download and install MySQL on their own, do I have to have a commercial license?

如果我要求客户端自己下载安装MySQL,我是否必须有商业许可证?

Any suggestions or direction would be great, thank you.

任何建议或方向都会很棒,谢谢。

采纳答案by tuinstoel

There are sqlite servers that make it possible to use sqlite in a multi user environment. Read here: http://www.sqlite.org/cvstrac/wiki?p=SqliteNetwork. I don't know how those solutions perform and scale.

有一些sqlite 服务器可以在多用户环境中使用sqlite。在这里阅读:http: //www.sqlite.org/cvstrac/wiki?p=SqliteNetwork。我不知道这些解决方案的性能和规模如何。

回答by James Kolpack

You may be able to use the Sqlite file on a shared network drive as you described, depending on the underlying filesystem:

您可以按照您的描述在共享网络驱动器上使用 Sqlite 文件,具体取决于底层文件系统:

http://www.sqlite.org/faq.html#q5

http://www.sqlite.org/faq.html#q5

Multiple processes can have the same database open at the same time. Multiple processes can be doing a SELECT at the same time. But only one process can be making changes to the database at any moment in time, however.

SQLite uses reader/writer locks to control access to the database. (Under Win95/98/ME which lacks support for reader/writer locks, a probabilistic simulation is used instead.) But use caution: this locking mechanism might not work correctly if the database file is kept on an NFS filesystem. This is because fcntl() file locking is broken on many NFS implementations. 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.

多个进程可以同时打开同一个数据库。多个进程可以同时执行 SELECT。但是,任何时候只有一个进程可以对数据库进行更改。

SQLite 使用读/写锁来控制对数据库的访问。(在不支持读写器锁的 Win95/98/ME 下,使用概率模拟代替。)但要小心:如果数据库文件保存在 NFS 文件系统上,这种锁定机制可能无法正常工作。这是因为 fcntl() 文件锁定在许多 NFS 实现中被破坏。如果多个进程可能同时尝试访问该文件,则应避免将 SQLite 数据库文件放在 NFS 上。在 Windows 上,Microsoft 的文档说,如果您没有运行 Share.exe 守护程序,则锁定可能无法在 FAT 文件系统下工作。对 Windows 有很多经验的人告诉我,网络文件的文件锁定非常有问题,而且不可靠。如果他们说的是真的,

回答by Hugues Van Landeghem

I think that Firebirdcan be a very good choice

我认为Firebird是一个非常好的选择

  • It's free
  • embedded version exist
  • 免费
  • 存在嵌入式版本

回答by Rippo

What about SQL Server Express, its free and should stop you having to rewrite most of your code,

SQL Server Express怎么样,它是免费的,应该不需要你重写大部分代码,

回答by driis

I don't know why you assume that the data file will be corrupted if you put it on a network drive and let multiple instances of your app access it at the same time. If you do mainly reading, you should be alright. If you do a lot of writes, you will probably suffer a performance hit, since only one instance can write at the same time. (See http://www.sqlite.org/faq.html)

我不知道为什么您认为如果将数据文件放在网络驱动器上并让您的应用程序的多个实例同时访问它,数据文件会损坏。如果你主要做阅读,你应该没问题。如果您进行大量写入,您可能会遭受性能损失,因为只有一个实例可以同时写入。(见http://www.sqlite.org/faq.html

If you do a lot of writes, you probably will need a standalone server installation - have you considered MS SQL Server Express ? Should be easy and simple to get up and running.

如果你写了很多东西,你可能需要一个独立的服务器安装——你考虑过 MS SQL Server Express 吗?启动和运行应该简单易行。

回答by PrestonDocks

Too late I know, but no one these days should have a need to write an application without a framework that offers database abstraction.

我知道为时已晚,但如今没有人需要编写没有提供数据库抽象框架的应用程序。

Personally I use Web2py which is a python based Web Framework. By default it uses SQLite which is great for single user apps on the local desktop or small to medium apps on the local network which are mainly read operations. However if I decided to increase the scope of the app usage, I would simply change the connection string in the database modal to use another database. Web2py or any other framework worth using would simply rewrite the SQL statements to meet the new requirements.

我个人使用 Web2py,它是一个基于 Python 的 Web 框架。默认情况下,它使用 SQLite,它非常适合本地桌面上的单用户应用程序或本地网络上主要是读取操作的中小型应用程序。但是,如果我决定增加应用程序的使用范围,我只需将数据库模式中的连接字符串更改为使用另一个数据库。Web2py 或任何其他值得使用的框架只需重写 SQL 语句即可满足新要求。

回答by Ayhan

use this code on your connection string after that multiple user can insert,delete,select e.t.c. in your database without issue.

在多个用户可以在您的数据库中插入、删除、选择等之后,在您的连接字符串上使用此代码而不会出现问题。

SQLiteConnection con = new SQLiteConnection("Data Source=D:\yourdatabase.db;Count Changes=off;Journal Mode=off;Pooling=true;Cache Size=10000;Page Size=4096;Synchronous=off");

SQLiteConnection con = new SQLiteConnection("Data Source=D:\yourdatabase.db;Count Changes=off;Journal Mode=off;Pooling=true;Cache Size=10000;Page Size=4096;Synchronous=off");

回答by Stephen C

If I require the client to download and install MySQL on their own, do I have to have a commercial license?

如果我要求客户端自己下载安装MySQL,我是否必须有商业许可证?

No.

不。

The value of a MySQL commercial license is that it allows you to distribute standard MySQL or a modified MySQL in binary form withoutthe oblihation to also distribute source code. It also gives you access to support.

MySQL 商业许可证的价值在于它允许您以二进制形式分发标准 MySQL 或修改后的 MySQL,而无需分发源代码。它还使您能够获得支持。

However, if the user obtains MySQL themselves from Oracle, the GPL places no obligations on you to provide them MySQL source code. They can get it from Oracle. Indeed, Oracle is obliged to provide it, so long as they distribute under the GPL.

但是,如果用户自己从 Oracle 获得 MySQL,则 GPL 不要求您向他们提供 MySQL 源代码。他们可以从 Oracle 获取。事实上,甲骨文有义务提供它,只要他们在 GPL 下分发。