2011-03-04 100 views
0

對不起,我再次發佈此問題。我搜索了它,發現了很多帖子和線程在stackoverflow和其他人,但沒有人爲我而戰。
我運行我的Windows窗體應用程序時出現此錯誤消息。 這是我App.config文件:無法從NHibernate.Driver.SQLiteDriver創建驅動程序

<?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> 

我使用Visual Studio 2010和Windows Server 2008 R2 64位上。 我的項目配置是X86,我嘗試了System.Data.SQLite.dll文件的x86,x64和ManagedOnly版本,但似乎沒有任何工作。

任何人都可以幫助我嗎?
P.S:我知道這裏有類似的線索,但請不要關閉此線程,因爲沒有任何解決方案適用於我。

謝謝。

+0

你得到什麼錯誤?你能發佈Exception和Stacktrace嗎? – 2011-03-04 09:28:54

回答

1

以下是錯誤:

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) 
0

的錯誤似乎與司機創作,這個建議,我認爲司機是不是你的系統上安裝正確。我剛剛測試了這一點,它爲我工作(好吧我使用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> 
0

似乎SQLite的組件沒有加載因此錯誤:

無法創建從NHibernate.Driver.SQLiteDriver驅動程序。 ---> System.Reflection.TargetInvocationException:調用的目標引發了異常。 ---> NHibernate.HibernateException:無法找到程序集SQLite.NET中的IDbCommand和IDbConnection實現。確保程序集SQLite.NET位於應用程序目錄或全局程序集緩存中。如果程序集位於GAC中,請使用應用程序配置文件中的元素指定程序集的全名。

,你可以使用預裝組件:

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); 
     } 
    } 
} 
相關問題