【问题标题】:Could not create the driver from NHibernate.Driver.SQLite20Driver无法从 NHibernate.Driver.SQLite20Driver 创建驱动程序
【发布时间】:2011-05-12 00:16:18
【问题描述】:

这是引发异常的代码

   public Configuration GetConfiguration()
    {
        var persister = SQLiteConfiguration
            .Standard
            .UsingFile("Test.db")
            .ShowSql();


        var configuration = Fluently
            .Configure()
            .Database(persister)
            .Mappings(map => map.FluentMappings.AddFromAssemblyOf<WordMap>())
            .BuildConfiguration();

        new SchemaExport(configuration).Execute(true, true, false);

        return configuration;

    }

完整的异常文本:

失败:NHibernate.HibernateException:无法创建驱动程序 来自 NHibernate.Driver.SQLite20Driver,NHibernate,版本=2.1.2.4000, 文化=中性,PublicKeyToken=aa95f207798dfdb4。

----> System.Reflection.TargetInvocationException : 调用目标抛出异常。

----> NHibernate.HibernateException : 程序集 System.Data.SQLite 中的 IDbCommand 和 IDbConnection 实现可以 找不到。确保程序集 System.Data.SQLite 位于 在应用程序目录或全局程序集缓存中。如果 程序集在 GAC 中,使用元素 应用程序配置文件指定的全名 组装。

NHibernate 的版本是 2.1.2.4000
System.Data.SQLite 的版本是 1.0.66.0
目标框架是 3.5 (x86)
System.Data.SQLite 的本地副本已打开。

可能出了什么问题?

【问题讨论】:

标签: c# nhibernate sqlite


【解决方案1】:

只需将 System.Data.SQLite.dll 库复制到应用程序的基目录(尤其是放置 NHibernate.dll 库的位置)。 您甚至不需要将它添加为 VS 下的引用。

问候
布罗内克

【讨论】:

  • 安装 System.Data.SQLite nuget 包也可以正常工作。
  • 仅供参考,它是:安装 System.Data.SQLite.Core 包,它添加了 System.Data.SQLite 引用也使它工作。 (即,您不需要所有其他的东西......比如 EF6 支持...... System.Data.SQLite 包附带的。)
【解决方案2】:

我刚刚安装了 SQLite NuGet 包,它对我有用。

【讨论】:

    【解决方案3】:

    我通过将 useLegacyV2RuntimeActivationPolicy="true" 添加到 app.config 来解决这个问题。见Problem Upgrading NHibernate SQLite Application to .Net 4.0

    【讨论】:

      【解决方案4】:

      无法从 NHibernate.Driver.SQLite20Driver 创建驱动程序,NHibernate,Version=2.1.2.4000,Culture=neutral,PublicKeyToken=aa95f207798dfdb4

      解决方案:

      测试设置: 选择主机 选择在 64 位机器上以 64 位进程运行测试

      希望我能帮上忙。

      快乐的编码

      【讨论】:

        【解决方案5】:

        如果 LocalCopy 已打开,它是否为启动项目中的 System.Data.SQLite 版本打开,因为它将在其中查找它,而不是在子项目的 bin 目录中。

        【讨论】:

          【解决方案6】:

          在 VS 2019 中,在 Test -> Processor Architecture for AnyCPU Projects 中,我从 x64 更改为 Auto,它解决了我的问题。

          【讨论】:

            猜你喜欢
            • 2011-09-02
            • 2018-05-17
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2010-11-11
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多