当前位置:网站首页>C# SQLite Database Locked exception
C# SQLite Database Locked exception
2022-07-24 15:11:00 【ITKEY_】
The phenomenon
There is no problem when querying , But in Insert It will be reported that the database is locked .
Cause analysis
Maybe the code is connected to the database somewhere , I forgot to close it .
terms of settlement
I haven't completely understood the principle , But according to the following writing method, it does solve the problem .
Somewhere , The connection is open . Get rid of OpenConnection and CloseConnection change ExecuteNonQuery This :
using (SQLiteConnection c = new SQLiteConnection(ConnectionString))
{
c.Open();
using (SQLiteCommand cmd = new SQLiteCommand(sql, c))
{
cmd.ExecuteNonQuery();
}
}
Besides , Change the way of reading data to :
using (SQLiteConnection c = new SQLiteConnection(ConnectionString))
{
c.Open();
using (SQLiteCommand cmd = new SQLiteCommand(sql, c))
{
using (SQLiteDataReader rdr = cmd.ExecuteReader())
{
...
}
}
}
Don't try to manage the connection pool yourself like here . First , It is much more complex than the code you write , But second , It's already in SQLiteConnection Inside the object . Last , If you don't use it using, You don't handle these objects correctly , You will eventually encounter problems like you see now .
Reference resources
https://stackoverflow.com/questions/17592671/sqlite-database-locked-exception
边栏推荐
- Deep learning 1 perceptron and implementation of simple back propagation network
- 【OpenCV 例程300篇】238. OpenCV 中的 Harris 角点检测
- Rest style
- pytorch with torch.no_grad
- Date processing bean
- Under multi data source configuration, solve org.apache.ibatis.binding Bindingexception: invalid bound statement (not found) problem
- Applet tab
- 野火stm32霸道,通过固件库实现流水灯
- Production environment tidb cluster capacity reduction tikv operation steps
- Chiitoitsu
猜你喜欢

Detailed explanation of IO model (easy to understand)

《Route planning method for UAV in unknown environment based on improved SAS algorithm》翻译

Outlook tutorial, how to create tasks and to DOS in outlook?

Outlook tutorial, how to set rules in outlook?

Production environment tidb cluster capacity reduction tikv operation steps

Performance test - analyze requirements

MongoDB入门学习

文件操作详解

JSON file editor

zabbix管理员忘记登录密码
随机推荐
Preparation of mobile end test cases
Circular structure practice
【USENIX ATC'22】支持异构GPU集群的超大规模模型的高效的分布式训练框架Whale
Unity 使用NVIDIA FleX for Unity插件实现制作软体、水流流体、布料等效果学习教程
Which securities company is the best and safest to open an account? How to open an account and speculate in stocks
Class loading mechanism and parental delegation mechanism
Usage differences of drop, truncate and delete
REST风格
老虎口瀑布:铜梁版小壶口瀑布
深度学习中的学习率调整策略(1)
LeetCode高频题56. 合并区间,将重叠的区间合并为一个区间,包含所有区间
Leetcode high frequency question 56. merge intervals, merge overlapping intervals into one interval, including all intervals
zabbix管理员忘记登录密码
(零九)Flask有手就行——Cookie和Session
pytorch with torch.no_ grad
Operation of MySQL Library
Data analysis and mining 1
Machine learning practice notes
spark:指定日期输出相应日期的日志(入门级-简单实现)
Similarities and differences between nor flash and NAND flash