gpt4 book ai didi

c# - 多个更新语句抛出 "cannot open"

转载 作者:行者123 更新时间:2023-11-30 22:22:44 26 4
gpt4 key购买 nike

当我尝试在 WinRT 中的 SQLite 上的同一事务中对同一表执行多个更新时,出现“无法打开”异常。

我已经为这个用例创建了一个示例应用程序。下面是点击第一个按钮的代码,我在事务中创建一个表,点击另一个按钮,我试图第二次更新同一条记录。在那里,它抛出一个“无法打开”异常。

app code :

private SQLiteConnection getConnection()
{
var connection = SQLiteConnectionPool.Shared.GetConnection(
new SQLiteConnectionString("sample.db", false));
return connection;
}

private void Button_Click_1(object sender, RoutedEventArgs e)
{
SQLiteConnection con = getConnection();
con.BeginTransaction();
{
try
{
var command = new SQLiteCommand(con) {
CommandText =
@"create table konysyncMETAINFO (
id bigint not null,
versionnumber int,
lastserversynccontext nvarchar(1000),
filtervalue nvarchar(1000),
replaysequencenumber integer,
lastgeneratedid integer,
scopename nvarchar(100),
primary key (id))"
};
var xyz = (double)command.ExecuteNonQuery();

var command2 = new SQLiteCommand(con) {
CommandText =
@"insert into konysyncMETAINFO
(id,scopename,versionnumber,lastserversynccontext,
replaysequencenumber,lastgeneratedid)
values ('1','testscope','0','','0','-1')"
};
var xyz2 = (double)command2.ExecuteNonQuery();

var command3 = new SQLiteCommand(con) {
CommandText =
@"insert into konysyncMETAINFO
(id,scopename,versionnumber,lastserversynccontext,
replaysequencenumber,lastgeneratedid)
values ('2','testscope2','0','','0','-1')"
};
var xyz3 = (double)command3.ExecuteNonQuery();
con.Commit();
}
catch (Exception ex)
{
con.Rollback();
}
}
}

private void Button_Click_2(object sender, RoutedEventArgs e)
{
SQLiteConnection con = getConnection();
con.BeginTransaction();
{
try
{
var command = new SQLiteCommand(con) {
CommandText =
@"Update konysyncMETAINFO
set lastgeneratedid='4'
WHERE scopename = 'testscope'"
};
var xyz = (double)command.ExecuteNonQuery();

//var command2 = new SQLiteCommand(con) { CommandText = "insert into konysyncMETAINFO (id,scopename,versionnumber,lastserversynccontext,replaysequencenumber,lastgeneratedid) values ('3','testscope3','0','','0','-1')" };
//var xyz2 = (double)command2.ExecuteNonQuery();

var command3 = new SQLiteCommand(con) {
CommandText =
@"Update konysyncMETAINFO
set lastgeneratedid='3'
WHERE scopename = 'testscope'"
};
var xyz3 = (double)command3.ExecuteNonQuery();
con.Commit();
}
catch (Exception ex)
{
con.Rollback();
}
}
}

最佳答案

您可能偶然发现了 the same bug在我拥有的 sqlite-net 中。我创建了 a fix它已经被拉回主叉,但还没有新的 release on NuGet自那以后。你可以 download the latest sources directly并检查它是否解决了您的问题。

关于c# - 多个更新语句抛出 "cannot open",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13705341/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com