.NET Core SQLite 'database is locked' 仅在 Linux
.NET Core SQLite 'database is locked' only on Linux
我有一个问题,我有一个小程序可以检索 CSV 文件并将其转换为 Sqlite 数据库。在 Windows 上没问题,它工作得很好。但是,在 Linux 上,我收到一条错误消息:
string connectionString = "Data Source=" + PathFile + targetFile;
using (SqliteConnection m_dbConnection = new SqliteConnection(connectionString))
{
m_dbConnection.Open();
// Requêtes de création des tables
string sql = String.Empty;
sql = String.Concat(sql, "CREATE TABLE TARGETS (idTarget NUMERIC, customerId NUMERIC, numberCard TEXT, mail TEXT, mobile TEXT, bat NUMERIC);");
sql = String.Concat(sql, "CREATE TABLE COLUMNS (idColumn NUMERIC, name TEXT, isVariable NUMERIC);");
sql = String.Concat(sql, "CREATE TABLE ROW (idTarget NUMERIC, idColumn TEXT, value TEXT);");
// Execution des requêtes de création
using (SqliteCommand command = new SqliteCommand(sql, m_dbConnection))
{
countRow += command.ExecuteNonQuery(); // <===== /!\ Exception here
}
}
Unhandled Exception: Microsoft.Data.Sqlite.SqliteException: SQLite Error 5: 'database is locked'.
at Microsoft.Data.Sqlite.SqliteException.ThrowExceptionForRC(Int32 rc, sqlite3 db)
at Microsoft.Data.Sqlite.SqliteCommand.ExecuteReader(CommandBehavior behavior)
at Microsoft.Data.Sqlite.SqliteCommand.ExecuteNonQuery()
at Mailing.Service.ServiceFile.ConvertCSVToSQLite(String sourceFile, String targetFile)
at Mailing.Service.ServiceFile.UploadFile(Byte[] byteFile, String filename, TypeCanal canal, Int32 idMailing, Boolean async)
at MailingAutomator.Program.Main(String[] args) in Program.cs:line 64
对于Microsoft.Data.Sqlite,Linux和Windows之间有什么不同吗?
与 Linux 我在挂载的 NAS 上读写有关吗?访问问题? sqlite 数据库已创建但为空。
.NET 核心 2.2
Microsoft.Data.Sqlite
Ubuntu16.04
编辑:一些消息:
当我在其他 ubuntu 服务器上使用 samba 共享时,它工作正常
但是在其他 Windows 共享上,我再次遇到此错误...日志文件出现并消失了几次。
我不明白,sqlite 文件已创建但为空
我的代码没问题。
我通过将 "nobrl" 添加到我的挂载命令解决了我的问题并且它有效。
nobrl : Do not send byte range lock requests to the server. This is necessary for certain applications that break with cifs style mandatory byte range locks (and most cifs servers do not yet support requesting advisory byte range locks).
我有一个问题,我有一个小程序可以检索 CSV 文件并将其转换为 Sqlite 数据库。在 Windows 上没问题,它工作得很好。但是,在 Linux 上,我收到一条错误消息:
string connectionString = "Data Source=" + PathFile + targetFile;
using (SqliteConnection m_dbConnection = new SqliteConnection(connectionString))
{
m_dbConnection.Open();
// Requêtes de création des tables
string sql = String.Empty;
sql = String.Concat(sql, "CREATE TABLE TARGETS (idTarget NUMERIC, customerId NUMERIC, numberCard TEXT, mail TEXT, mobile TEXT, bat NUMERIC);");
sql = String.Concat(sql, "CREATE TABLE COLUMNS (idColumn NUMERIC, name TEXT, isVariable NUMERIC);");
sql = String.Concat(sql, "CREATE TABLE ROW (idTarget NUMERIC, idColumn TEXT, value TEXT);");
// Execution des requêtes de création
using (SqliteCommand command = new SqliteCommand(sql, m_dbConnection))
{
countRow += command.ExecuteNonQuery(); // <===== /!\ Exception here
}
}
Unhandled Exception: Microsoft.Data.Sqlite.SqliteException: SQLite Error 5: 'database is locked'.
at Microsoft.Data.Sqlite.SqliteException.ThrowExceptionForRC(Int32 rc, sqlite3 db)
at Microsoft.Data.Sqlite.SqliteCommand.ExecuteReader(CommandBehavior behavior)
at Microsoft.Data.Sqlite.SqliteCommand.ExecuteNonQuery()
at Mailing.Service.ServiceFile.ConvertCSVToSQLite(String sourceFile, String targetFile)
at Mailing.Service.ServiceFile.UploadFile(Byte[] byteFile, String filename, TypeCanal canal, Int32 idMailing, Boolean async)
at MailingAutomator.Program.Main(String[] args) in Program.cs:line 64
对于Microsoft.Data.Sqlite,Linux和Windows之间有什么不同吗? 与 Linux 我在挂载的 NAS 上读写有关吗?访问问题? sqlite 数据库已创建但为空。
.NET 核心 2.2 Microsoft.Data.Sqlite Ubuntu16.04
编辑:一些消息: 当我在其他 ubuntu 服务器上使用 samba 共享时,它工作正常 但是在其他 Windows 共享上,我再次遇到此错误...日志文件出现并消失了几次。 我不明白,sqlite 文件已创建但为空
我的代码没问题。 我通过将 "nobrl" 添加到我的挂载命令解决了我的问题并且它有效。
nobrl : Do not send byte range lock requests to the server. This is necessary for certain applications that break with cifs style mandatory byte range locks (and most cifs servers do not yet support requesting advisory byte range locks).