Ado.net firebird commit向表

时间:2016-01-18 01:57:22

标签: c# sql transactions firebird rdbms

我正在使用firebird ado.net客户端为我们公司的每个订单的“订单列表”添加新行到数据库。我写的代码适用于列出项目,但插入新代码不会出现在其他地方(例如在flamerobin中)。我认为发生的事情是事务没有被提交,因为它在我的代码中被识别(不能添加重复值)。 代码:

using (FbConnection fbCon = new FbConnection)
{
    fbCon.Open();
    ***command w/ parameterised command string***
    using (FbTransaction fbTrans = fbCon.BeginTransaction())
    using FbCommand orderCommand = new FbCommand(cmdString, fbCon, fbTrans)
    {
    ***Adding parameters and values***
    try
    {
        int recordsAffected = orderCommand.ExecuteNonQuery();
        fbTrans.Commit();
    }
    catch (FbException E)
    {
    fbTrans.Rollback();
    fbCon.Close();
    throw E
    }
}

recordsAffected返回1,但我无法在flamerobin或db管理程序中看到更新的值。我错过了什么吗?

1 个答案:

答案 0 :(得分:0)

如果有其他人遇到此问题,则在Visual Studio的调试设置中。 https://visualstudiomagazine.com/blogs/tool-tracker/2012/05/dealing-with-local-databases-or-why-your-updates-dont-stick.aspx非常清楚地解释了,但基本上VS在你的项目的bin / Debug中创建了你的数据库的副本(表面上是为了不弄乱你的数据),但如果你真的需要在外部使用/查看数据,要么链接你的调试数据库的外部应用程序(例如,flamerobin)。如果您希望保留更新,则可能还需要将项目数据库设置设置为“如果更新则复制”,因为默认设置会在每次运行c#app时将数据库复制到文件夹中。