0

新手来了

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

我的系统配置:

  • Firebird-2.5.0.26074-0_Win32_embed
  • Firebird ADO.NET 数据提供者 2.6.5
  • FluentNHibernate 1.2.0.712
  • NHibernate 3.1.0.4000
  • 视觉工作室 2010 SP1
  • .NET 框架 4.0
  • 视窗 7 64 位

以下是我采取的步骤:

  1. Firebird-2.5.0.26074-0_Win32_embed.zip这里下载。
  2. NETProvider-2.6.5.zip这里下载。
  3. 在 Visual Studio 2010 中创建一个新的控制台应用程序。
  4. 将 zip 文件的内容提取到.\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

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

下面是我的测试代码:

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; }
    }
}

有任何想法吗?谢谢。

4

2 回答 2

0

您是否尝试使用完整路径

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

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

于 2011-07-12T21:06:07.007 回答
0

删除 pdb 文件不会导致任何问题。当抛出异常时,它有助于获取行号。

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

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

维杰

于 2011-07-14T15:23:06.887 回答