【问题标题】:Can't get Firebird Embedded work with FluentNHibernate无法使用 FluentNHibernate 获得 Firebird Embedded 工作
【发布时间】:2011-07-11 14:03:57
【问题描述】:

这里是新手,

这是我第一次使用 Firebird。我想将 Firebird Embedded 与 FluentNHibernate 一起使用,但是当我尝试运行我的测试程序时它会抛出异常。测试项目可以从here下载。

我的系统配置:

  • Firebird-2.5.0.26074-0_Win32_embed
  • Firebird ADO.NET 数据提供程序 2.6.5
  • FluentNHibernate 1.2.0.712
  • NHibernate 3.1.0.4000
  • Visual Studio 2010 SP1
  • .NET Framework 4.0
  • Windows 7 64 位

以下是我采取的步骤:

  1. here下载Firebird-2.5.0.26074-0_Win32_embed.zip
  2. here下载NETProvider-2.6.5.zip
  3. 在 Visual Studio 2010 中创建一个新的控制台应用程序。
  4. 将压缩文件的内容解压到.\bin\Debug
  5. 编写测试代码(详见下文)。
  6. 按 F5。

但我在new SchemaExport(cfg).Create(false, true); 遇到以下异常:

FbException was unhandled by user code: Dynamic SQL Error SQL error code = -607 Invalid command Table A does not exist

经过进一步测试,我发现如果我从.\bin\Debug文件夹中删除NETProvider-2.6.5.zipFirebirdSql.Data.FirebirdClient.pdb文件。测试程序可以正常运行。但我不确定删除它是否会导致其他问题。

下面是我的测试代码:

class Program
{
    static void Main(string[] args)
    {
        ISessionFactory sessionFactory = BuildSessionFactory();
        using (ISession session = sessionFactory.OpenSession())
        {
            using (ITransaction trans = session.BeginTransaction())
            {                    
            }
        }
    }

    static ISessionFactory BuildSessionFactory()
    {
        string dbPath = "test.db";
        string connectionString = String.Format(
            "User=SYSDBA;Password=masterkey;Database={0};Dialect=3;Charset=UTF8;ServerType=1;",
            dbPath);

        if (File.Exists(dbPath))
            File.Delete(dbPath);

        FbConnection.CreateDatabase(connectionString);

        FirebirdConfiguration cfg = new FirebirdConfiguration()
            .ConnectionString(connectionString)
            .AdoNetBatchSize(100);

        ISessionFactory sessionFactory = Fluently.Configure()
            .Database(cfg)
            .Mappings(m => m.FluentMappings.Add(typeof(AMappings)))
            .ExposeConfiguration(BuildSchema)
            .BuildConfiguration()
            .BuildSessionFactory();

        return sessionFactory;
    }

    static void BuildSchema(Configuration cfg)
    {
        new SchemaExport(cfg).Create(false, true);
    }

    public class AMappings : ClassMap<A>
    {
        public AMappings()
        {
            Id(x => x.Id).GeneratedBy.HiLo("100");
            Map(x => x.Text);
        }
    }

    public class A
    {
        public virtual long Id { get; private set; }
        public virtual string Text { get; set; }
    }
}

有什么想法吗?谢谢。

【问题讨论】:

  • 我的回答(下面给出了流畅的 NH 初始化)证明对您有用吗?
  • @Vijay,抱歉我的回复迟了。经过多次测试,我仍然得到异常。我暂时切换回 SQLite,因为我需要尽快完成当前的项目。当我完成当前项目时,我会再试一次 Firebird。感谢您的帮助和跟进。
  • 只是为了让您知道您的机器上发生了其他事情,因为我刚刚复制并粘贴了您的代码以尝试修复它。但它刚刚奏效!我使用您在表中映射到表的类在表中插入了一行。同样在flamerobin中打开数据文件,确认表和行的存在。 *** 唯一的区别是我使用了 fluentnhibernate-NH3.1-1.2.zip *** - Vijay
  • @Vijay,感谢您的测试!我刚刚将我的测试项目(dl.dropbox.com/u/1421509/forums/stackoverflow.com/…)复制到另一台机器(XP 32 位,Visual Studio 2010(无 SP1),但不幸遇到了同样的异常。请您上传您的测试项目(或检查我的测试项目是否可以在你的机器上运行)?非常感谢!
  • 这里是下载链接 - 如果它适合你,请告诉我:skydrive.live.com/…

标签: c# nhibernate fluent-nhibernate firebird firebird2.5


【解决方案1】:

删除 pdb 文件不会导致任何问题。在抛出异常时获取行号很有帮助。

我在混合 32 位和 64 位的东西时也遇到了麻烦。所以现在我在 64 位平台上使用 FB 嵌入式 64 位,在 32 位平台上使用 32 位,我从来没有遇到过任何问题。

尝试清理您的调试文件夹并重新复制 FB 64 位文件,看看是否有效。

维杰

【讨论】:

  • 感谢您的回复。不幸的是,当我在一个新的干净的 64 位项目中使用 64 位版本的 Firebird 时,我遇到了同样的异常(请参阅上面对 Hugues 的完整回复)。异常消息Table A does not exist 让我感到很不安。我可以简单地忽略它(只需删除pdb文件)只是一个误报吗?
【解决方案2】:

您是否尝试使用完整路径

dbPath = "c:\app\data\test.gdb";

我不太了解 dotnet 驱动程序,但通常使用 firebird,我们放置完整路径。

【讨论】:

  • 感谢您的回复。但不幸的是,当我使用完整路径时,我遇到了同样的异常。
  • 为什么你在 windows 64 位上使用 win32 fb ?
  • 我只是厌倦了 64 位版本的 Firebird。我在一个新的 64 位控制台应用程序上对其进行了测试(使用上面相同的测试代码),但不幸的是得到了与 32 位 Firebird 相同的异常。我还在 32 位控制台应用程序上尝试了 64 位 Firebird,但在 FbConnection.CreateDatabase(connectionString); 处得到了 BadImageFormatException was unhandled 异常。
猜你喜欢
  • 2016-09-14
  • 1970-01-01
  • 2014-12-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-02
  • 2012-06-14
相关资源
最近更新 更多