C#操作sqlite数据库显示database is locked

王大凤 2018-06-11 08:32:56
代码:
string consql = "Data Source=SHbook.db; Version=3;";
string password = "";
string oldpass = TextBoxOldPass.Text.Trim();
string newpass = TextBoxNewPass.Text.Trim();

using (SQLiteConnection con = new SQLiteConnection(consql))
{
con.Open();

string sql = "select * from [User] where UserName = '" + username + "';";
using (SQLiteCommand com = new SQLiteCommand(sql, con))
{
using (SQLiteDataReader reader = com.ExecuteReader())
{
if (reader.Read())
{
password = reader.GetString(reader.GetOrdinal("Password"));
password = password.Trim();
}
reader.Close();
reader.Dispose();
}
}
con.Close();
}

if (string.Compare(password, oldpass) == 0)
{
//数据库更新语句
using (SQLiteConnection con1 = new SQLiteConnection(consql))
{
con1.Open();

string sql = "update [User] set Password = '" + newpass + "'where UserName ='" + username + "';";
using (SQLiteCommand com1 = new SQLiteCommand(sql, con1))
{

MessageBox.Show("aaa");

int r = com1.ExecuteNonQuery(); 问题是执行到这句出错
MessageBox.Show(Convert.ToString(r));
if (r > 0)
{
MessageBox.Show("999");
if (MessageBox.Show("修改密码成功", "提示", MessageBoxButtons.OK) == DialogResult.OK)
{
this.Close();

}
}

}
}
...全文
994 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
编程有钱人了 2018-06-13
  • 打赏
  • 举报
回复
文件可能被别的查看器开着,或者把文件权限打开
王大凤 2018-06-11
  • 打赏
  • 举报
回复
引用 1 楼 nry19871012 的回复:
有多并发吗?
不是啊,我就是单线程的,顺序执行。
nry19871012 2018-06-11
  • 打赏
  • 举报
回复
有多并发吗?

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧