问题描述
我正在使用 c# 应用程序并在服务器机器上运行该应用程序作为 Windows 服务.当我从客户端机器执行插入、更新删除操作时,它会引发数据库锁定错误,如下所示,
I am using c# application and running the application in server machine as windows service.When i perform insert , update delete operation from client machine it throws database lock error as below,
database is locked
at System.Data.SQLite.SQLite3.Step(SQLiteStatement stmt)
at System.Data.SQLite.SQLiteDataReader.NextResult()
at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave)
at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.SQLite.SQLiteCommand.ExecuteNonQuery()
at System.Data.SQLite.SQLiteTransaction.Commit()
下面是我的代码
public int ExecuteNonQuerySQL(SQLiteCommand cmd)
{
int ireturn = 0;
if (conn.State != ConnectionState.Open)
Open(DataFile);
using (SQLiteTransaction dbtrans = conn.BeginTransaction(IsolationLevel.ReadCommitted))
{
using (cmd.Connection=conn)
{
cmd.CommandText =cmd.CommandText ;
cmd.Transaction = dbtrans;
ireturn = cmd.ExecuteNonQuery();
dbtrans.Commit();
cmd.Dispose();
}
}
}
请帮助我,我已经做了很多谷歌搜索,我必须找到一些解决方案来解决这个问题.问候
Please help me in this , I have done lot of googling and i must find some solution to solve this .Regards
推荐答案
从提供的代码来看,似乎您没有关闭连接.
From the code provided it seems that you do not close the connecttion.
还要注意事实,不知道它是否与您的情况相关,Sqlite
在支持并发 inserts
方面不是很好,有时 db 得到锁,如果您从多个线程对其进行操作.
Pay attention also on fact, don't know if it's relevant in your case or not, that the Sqlite
not very good on supporting concurent inserts
and sometimes db got lock, if you operate on it from multiple threads.
这篇关于sqlite 数据库被锁定异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!