2011-08-25 89 views
0

我在C#中使用Firebird的dot net提供程序运行一些SQL命令。具体来说,我正在更改数据库模式,并进行数据更新等。Firebird点网络提供者没有完全执行查询?

作为我的处理的一部分,我创建一个新表,运行查询以从旧表中复制数据,然后删除旧表。

当我做这个火鸟生成和错误:

unsuccessful metadata update object is in use

我已经做了一些看,它似乎查询复制的数据没有被“清除”我们什么呢。我的意思是当我检查Firebird中的监控表时,我的c#执行已暂停,我在MON$STATEMENTS表中看到查询为非活动状态。这是我运行一个提交语句后。

我的问题:

有没有办法暂停,或等待,或强制查询,全面完成之前,我尝试运行下一个命令?

当我在ISQL中运行相同的查询序列时,它可以很好地工作。有什么不同的ISQL,我可以强制点网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; 
+0

作为参考,我使用火鸟2.1.0窗口建设,我使用我相信DDEXProvider-2.0.1的事情 – Beau

回答

0

好了,可怕的问题的解决方案:

我居然能得到这个由工作关闭和处理连接,然后重新连接。这导致“卡住”查询以某种方式被移除,然后我可以执行表格放置命令。所以顺序看起来像这样:

// 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 connection entirely and start a new one 
// so the table can be dropped 

Connection.Close(); 
Connection.Dispose(); 

// build connection string 
FbConnectionStringBuilder csb = new FbConnectionStringBuilder(); 
csb.DataSource ... etc... 

// connect 
Connection = new FbConnection(connectionString); 
Connection.Open(); 

// Now have new connection that does not have weird 
// lingering query, and table can now be dropped 
// ----------------- 



// drop the old table 
commandString = "DROP TABLE ..."; 

mtransaction = Connection.BeginTransaction(IsolationLevel.Serializable); 
FbCommand command = new FbCommand(commandString, Connection, mtransaction); 
command.ExecuteNonQuery(); 

// this no longer fails because the connection was complete closed 
// and re-opened 
transaction.Commit(); 
transaction.Dispose(); 
transaction = null; 

注意:我对此解决方案非常不满意。它有效,但我不知道为什么。我不得不这样做放弃一张桌子,这对我来说过分而不切实际。我会非常感谢任何人在这件事上可能提供的见解!

0

我相信我遇到了类似的事情。我的猜测是,根本原因似乎是一个特点:MVCC。当我混淆模式,或只删除表然后重新创建时,Visual Studio通常会将其保持为打开状态。我只是重新启动服务,一切都很好。

1

我遇到了同样的问题,并验证了Beau's(原始)修补程序。然而,我发现了一个简单的解决方案:在事务提交后处理命令!然后重新连接不再需要。

mtransaction = Connection.BeginTransaction(IsolationLevel.Serializable); 
FbCommand command = new FbCommand(commandString, Connection, mtransaction); 
command.ExecuteNonQuery(); 
transaction.Commit(); 
command.Dispose(); // Thus! 
transaction.Dispose(); 

问候, 航标

+0

尼斯找到C#的一面!没有尝试过! – Beau