【发布时间】:2011-08-25 18:26:52
【问题描述】:
我正在 c# 中使用 Firebird 的 dot net 提供程序运行许多 SQL 命令。具体来说,我正在更改数据库架构,并进行数据更新等。
作为我处理的一部分,我创建了一个新表,运行查询以从旧表中复制数据,然后删除旧表。
当我这样做时,firebird 会生成和错误:
不成功的元数据更新对象正在使用中
我做了一些查看,它似乎复制数据的查询尚未“清除”我们或其他什么。我的意思是,当我在 C# 执行暂停的情况下检查 Firebird 中的监控表时,我看到 MON$STATEMENTS 表中的查询处于非活动状态。这是在我运行了提交语句之后。
我的问题:
在我尝试运行下一个命令之前,有没有办法暂停、等待或强制查询完全完成?
当我在 ISQL 中运行相同的查询序列时,它可以完美运行。有什么不同的 ISQL 我可以强制 dot net Firebird 提供程序这样做,这样它就不会保持这个查询打开或什么?
所以作为参考,代码看起来像这样(显然这是一个非常简化的):
// create the table
string commandString = "CREATE TABLE ...";
// run the command in a transaction and commit it
mtransaction = Connection.BeginTransaction( IsolationLevel.Serializable );
FbCommand command = new FbCommand(commandString, Connection, mtransaction);
command.ExecuteNonQuery();
transaction.Commit();
transaction.Dispose();
transaction = null;
// copy the data to the new table from the old
commandString = "INSERT INTO ...";
mtransaction = Connection.BeginTransaction(IsolationLevel.Serializable);
FbCommand command = new FbCommand(commandString, Connection, mtransaction);
command.ExecuteNonQuery();
transaction.Commit();
transaction.Dispose();
transaction = null;
// drop the old table
commandString = "DROP TABLE ...";
mtransaction = Connection.BeginTransaction(IsolationLevel.Serializable);
FbCommand command = new FbCommand(commandString, Connection, mtransaction);
command.ExecuteNonQuery();
// this command fails with the exception
// if I pause execution in c# before running this command, and
// use isql to look at the db I see the new table, and the data fully populated
// and I also see the inactive insert command in MON$STATEMENTS
transaction.Commit();
transaction.Dispose();
transaction = null;
【问题讨论】:
-
作为参考,我使用的是 Firebird 2.1.0 windows build,我相信 DDEXProvider-2.0.1 用于 c# 方面