无法从 NHibernate.Driver.SQLiteDriver 创建驱动程序

发布于 2024-10-20 06:44:02 字数 1634 浏览 3 评论 0 原文

很抱歉我再次发布这个问题。我用谷歌搜索它并在 stackoverflow 和其他上找到了许多帖子和线程,但没有一个适合我。
当我运行 Windows 窗体应用程序时,我收到此错误消息。 这是我的 App.config 文件:

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"/>
  </configSections>
  <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory name="NHibernate.Test">
      <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
      <property name="connection.driver_class">NHibernate.Driver.SQLiteDriver</property>
      <property name="connection.connection_string">
        Data Source=nhibernate.db;Version=3;New=True;
      </property>
      <property name="dialect">NHibernate.Dialect.SQLiteDialect</property>
      <property name="query.substitutions">true=1;false=0</property>
      <property name="proxyfactory.factory_class">
        NHibernate.ByteCode.LinFu.ProxyFactoryFactory,NHibernate.ByteCode.LinFu
      </property>
    </session-factory>
  </hibernate-configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
</configuration>

我正在 Windows Server 2008 R2 64 位上使用 Visual Studio 2010。 我的项目配置是 X86,我尝试了 System.Data.SQLite.dll 文件的 x86、x64 和 ManagedOnly 版本,但似乎都不起作用。

谁能帮我解决这个问题吗?
PS:我知道有与此类似的线程,但请不要关闭此线程,因为没有一个解决方案对我有用。

谢谢。

I am sorry I am posting this question again. I googled for it and found many posts and threads on stackoverflow and other ones, but none wokred for me.
I get this error message when I run my Windows Forms Application.
Here is my App.config file:

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"/>
  </configSections>
  <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory name="NHibernate.Test">
      <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
      <property name="connection.driver_class">NHibernate.Driver.SQLiteDriver</property>
      <property name="connection.connection_string">
        Data Source=nhibernate.db;Version=3;New=True;
      </property>
      <property name="dialect">NHibernate.Dialect.SQLiteDialect</property>
      <property name="query.substitutions">true=1;false=0</property>
      <property name="proxyfactory.factory_class">
        NHibernate.ByteCode.LinFu.ProxyFactoryFactory,NHibernate.ByteCode.LinFu
      </property>
    </session-factory>
  </hibernate-configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
</configuration>

I am using Visual Studio 2010, on Windows Server 2008 R2 64 Bit.
My project configuration is X86, and I tried the x86, x64 and ManagedOnly versions of the System.Data.SQLite.dll file, but none seemed to work.

Can anyone please help me with this?
P.S: I know there are similar threads to this one, but please don't close this thread because none of the solutions have worked for me.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

黯然 2024-10-27 06:44:02

这是错误:

NHibernate.HibernateException: Could not create the driver from NHibernate.Driver.SQLiteDriver. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> NHibernate.HibernateException: The IDbCommand and IDbConnection implementation in the assembly SQLite.NET could not be found. Ensure that the assembly SQLite.NET is located in the application directory or in the Global Assembly Cache. If the assembly is in the GAC, use <qualifyAssembly/> element in the application configuration file to specify the full name of the assembly.
   at NHibernate.Driver.ReflectionBasedDriver..ctor(String driverAssemblyName, String connectionTypeName, String commandTypeName)
   at NHibernate.Driver.SQLiteDriver..ctor()
   --- End of inner exception stack trace ---
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at NHibernate.Bytecode.ActivatorObjectsFactory.CreateInstance(Type type)
   at NHibernate.Connection.ConnectionProvider.ConfigureDriver(IDictionary`2 settings)
   --- End of inner exception stack trace ---
   at NHibernate.Connection.ConnectionProvider.ConfigureDriver(IDictionary`2 settings)
   at NHibernate.Connection.ConnectionProvider.Configure(IDictionary`2 settings)
   at NHibernate.Connection.ConnectionProviderFactory.NewConnectionProvider(IDictionary`2 settings)
   at NHibernate.Cfg.SettingsFactory.BuildSettings(IDictionary`2 properties)
   at NHibernate.Cfg.Configuration.BuildSettings()
   at NHibernate.Cfg.Configuration.BuildSessionFactory()
   at Employee.App.SessionProvider.get_Session() in C:\Users\Ako\documents\visual studio 2010\Projects\Employee\Employee.App\SessionProvider.cs:line 28
   at Employee.App.EmployeeManager.get_Session() in C:\Users\Ako\documents\visual studio 2010\Projects\Employee\Employee.App\EmployeeManager.cs:line 14
   at Employee.App.EmployeeManager.Save(Employee employee) in C:\Users\Ako\documents\visual studio 2010\Projects\Employee\Employee.App\EmployeeManager.cs:line 56
   at Employee.App.frmMain.frmMain_Load(Object sender, EventArgs e) in C:\Users\Ako\documents\visual studio 2010\Projects\Employee\Employee.App\frmMain.cs:line 23
   at System.Windows.Forms.Form.OnLoad(EventArgs e)
   at System.Windows.Forms.Form.OnCreateControl()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.Form.WmShowWindow(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Here is the error:

NHibernate.HibernateException: Could not create the driver from NHibernate.Driver.SQLiteDriver. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> NHibernate.HibernateException: The IDbCommand and IDbConnection implementation in the assembly SQLite.NET could not be found. Ensure that the assembly SQLite.NET is located in the application directory or in the Global Assembly Cache. If the assembly is in the GAC, use <qualifyAssembly/> element in the application configuration file to specify the full name of the assembly.
   at NHibernate.Driver.ReflectionBasedDriver..ctor(String driverAssemblyName, String connectionTypeName, String commandTypeName)
   at NHibernate.Driver.SQLiteDriver..ctor()
   --- End of inner exception stack trace ---
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at NHibernate.Bytecode.ActivatorObjectsFactory.CreateInstance(Type type)
   at NHibernate.Connection.ConnectionProvider.ConfigureDriver(IDictionary`2 settings)
   --- End of inner exception stack trace ---
   at NHibernate.Connection.ConnectionProvider.ConfigureDriver(IDictionary`2 settings)
   at NHibernate.Connection.ConnectionProvider.Configure(IDictionary`2 settings)
   at NHibernate.Connection.ConnectionProviderFactory.NewConnectionProvider(IDictionary`2 settings)
   at NHibernate.Cfg.SettingsFactory.BuildSettings(IDictionary`2 properties)
   at NHibernate.Cfg.Configuration.BuildSettings()
   at NHibernate.Cfg.Configuration.BuildSessionFactory()
   at Employee.App.SessionProvider.get_Session() in C:\Users\Ako\documents\visual studio 2010\Projects\Employee\Employee.App\SessionProvider.cs:line 28
   at Employee.App.EmployeeManager.get_Session() in C:\Users\Ako\documents\visual studio 2010\Projects\Employee\Employee.App\EmployeeManager.cs:line 14
   at Employee.App.EmployeeManager.Save(Employee employee) in C:\Users\Ako\documents\visual studio 2010\Projects\Employee\Employee.App\EmployeeManager.cs:line 56
   at Employee.App.frmMain.frmMain_Load(Object sender, EventArgs e) in C:\Users\Ako\documents\visual studio 2010\Projects\Employee\Employee.App\frmMain.cs:line 23
   at System.Windows.Forms.Form.OnLoad(EventArgs e)
   at System.Windows.Forms.Form.OnCreateControl()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.Form.WmShowWindow(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
南…巷孤猫 2024-10-27 06:44:02

该错误似乎与驱动程序创建有关,这表明驱动程序未正确安装在您的系统上。我刚刚测试过这个,它对我有用(好吧,我使用的是 monodevelop,而不是 VS),我从这里安装了 Sqlite 驱动程序:

ADO.NET 2.0 Provider for SQLite

然后我在 app.config 文件中使用了它:

<session-factory>            
        <property name="dialect">NHibernate.Dialect.SQLiteDialect</property>
        <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
        <property name="connection.driver_class">NHibernate.Driver.SQLiteDriver</property>
        <property name="connection.connection_string">Data Source=SimpleExample.sqlite;Version=3</property>
        <property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>         
        <mapping assembly="SimpleExample" />
    </session-factory>

The error appears to be with the driver creation, this suggests to me that the driver is not installed on your system correctly. I've just tested this and it works for me (ok I'm using monodevelop, not VS), I installed the Sqlite driver from here:

ADO.NET 2.0 Provider for SQLite

I then used this in my app.config file:

<session-factory>            
        <property name="dialect">NHibernate.Dialect.SQLiteDialect</property>
        <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
        <property name="connection.driver_class">NHibernate.Driver.SQLiteDriver</property>
        <property name="connection.connection_string">Data Source=SimpleExample.sqlite;Version=3</property>
        <property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>         
        <mapping assembly="SimpleExample" />
    </session-factory>
故乡的云 2024-10-27 06:44:02

看来 SQLite 程序集未加载,因此出现错误:

无法从 NHibernate.Driver.SQLiteDriver 创建驱动程序。 ---> System.Reflection.TargetInitationException:调用目标已引发异常。 ---> NHibernate.HibernateException:无法找到程序集 SQLite.NET 中的 IDbCommand 和 IDbConnection 实现。确保程序集 SQLite.NET 位于应用程序目录或全局程序集缓存中。如果程序集位于 GAC 中,请使用应用程序配置文件中的 element 指定程序集的全名。

您可以使用以下方法预加载程序集:

PreLoadAssembliesFromPath(AppDomain.CurrentDomain.BaseDirectory);

private static void PreLoadAssembliesFromPath(string p)
{
    //S.O. NOTE: ELIDED - ALL EXCEPTION HANDLING FOR BREVITY

    //get all .dll files from the specified path and load the lot
    FileInfo[] files = null;
    //you might not want recursion - handy for localised assemblies 
    //though especially.
    files = new DirectoryInfo(p).GetFiles("*.dll",SearchOption.AllDirectories);

    AssemblyName a = null;
    string s = null;
    foreach (var fi in files)
    {
        s = fi.FullName;
        //now get the name of the assembly you've found, without loading it
        //though (assuming .Net 2+ of course).
        a = AssemblyName.GetAssemblyName(s);
        //sanity check - make sure we don't already have an assembly loaded
        //that, if this assembly name was passed to the loaded, would actually
        //be resolved as that assembly.  Might be unnecessary - but makes me
        //happy :)
        if (!AppDomain.CurrentDomain.GetAssemblies().Any(assembly =>
          AssemblyName.ReferenceMatchesDefinition(a, assembly.GetName())))
        {
            //crucial - USE THE ASSEMBLY NAME.
            //in a web app, this assembly will automatically be bound from the 
            //Asp.Net Temporary folder from where the site actually runs.
            Assembly.Load(a);
        }
    }
}

it appears that the SQLite assembly is not loaded hence the error:

Could not create the driver from NHibernate.Driver.SQLiteDriver. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> NHibernate.HibernateException: The IDbCommand and IDbConnection implementation in the assembly SQLite.NET could not be found. Ensure that the assembly SQLite.NET is located in the application directory or in the Global Assembly Cache. If the assembly is in the GAC, use element in the application configuration file to specify the full name of the assembly.

you could preload the assembly using:

PreLoadAssembliesFromPath(AppDomain.CurrentDomain.BaseDirectory);

private static void PreLoadAssembliesFromPath(string p)
{
    //S.O. NOTE: ELIDED - ALL EXCEPTION HANDLING FOR BREVITY

    //get all .dll files from the specified path and load the lot
    FileInfo[] files = null;
    //you might not want recursion - handy for localised assemblies 
    //though especially.
    files = new DirectoryInfo(p).GetFiles("*.dll",SearchOption.AllDirectories);

    AssemblyName a = null;
    string s = null;
    foreach (var fi in files)
    {
        s = fi.FullName;
        //now get the name of the assembly you've found, without loading it
        //though (assuming .Net 2+ of course).
        a = AssemblyName.GetAssemblyName(s);
        //sanity check - make sure we don't already have an assembly loaded
        //that, if this assembly name was passed to the loaded, would actually
        //be resolved as that assembly.  Might be unnecessary - but makes me
        //happy :)
        if (!AppDomain.CurrentDomain.GetAssemblies().Any(assembly =>
          AssemblyName.ReferenceMatchesDefinition(a, assembly.GetName())))
        {
            //crucial - USE THE ASSEMBLY NAME.
            //in a web app, this assembly will automatically be bound from the 
            //Asp.Net Temporary folder from where the site actually runs.
            Assembly.Load(a);
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文