System.Data.SQLite not found on non-development PC
I created a C# Project in Visual Studio and used an assembly on t开发者_如何学运维he SQLite 4.0 ADO Library from http://sqlite.phxsoftware.com/.
The program runs fine on the development machine, but when I try to run it on another system, there always occurs an error, stating that System.Data.SQLite.dll cannot be found. I placed the file into the program directory. I also tried to put it into a directory that is listed under PATH. Any suggestions?
I'm using an openFileDialog to open the database. Here's the according code:
con = new SQLiteConnection();
OpenFileDialog ofd1 = new OpenFileDialog();
ofd1.Filter = "db Datei (*.db)|*.db|Alle Dateien (*.*)|*.*";
if (ofd1.ShowDialog() == DialogResult.OK)
filepath = ofd1.FileName;
filepath.Replace("\\", "\\\\");
con.ConnectionString = "Data Source= \"" + filepath + "\"";
[...]
As already mentioned, this works on the development machine (Windows 7, 64bit). The test machine runs in a virtualbox (Windows 7, 32bit). The following exception occurs:
System.IO.FileNotFoundException: Die Datei oder Assembly "System.Data.SQLite.dll" oder eine Abhängigkeit davon wurde nicht gefunden. Das angegebene Modul wurde nicht gefunden.
Dateiname: "System.Data.SQLite.dll"
bei WindowsFormsApplication1.Form1.button2_Click(Object sender, EventArgs e)
bei System.Windows.Forms.Control.OnClick(EventArgs e)
bei System.Windows.Forms.Button.OnClick(EventArgs e)
bei System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
bei System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
bei System.Windows.Forms.Control.WndProc(Message& m)
bei System.Windows.Forms.ButtonBase.WndProc(Message& m)
bei System.Windows.Forms.Button.WndProc(Message& m)
bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
bei System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Geladene Assemblys **************
mscorlib
Assembly-Version: 4.0.0.0.
Win32-Version: 4.0.30319.1 (RTMRel.030319-0100).
CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll.
----------------------------------------
WindowsFormsApplication1
Assembly-Version: 1.0.0.0.
Win32-Version: 1.0.0.0.
CodeBase: file:///C:/Users/andi/Documents/My%20Dropbox/Own%20Public%20Folders/Public%20(Andy%20Malessa)/juralookup(Wir%20brauchen%20dringend%20nen%20Namen)/DataManagementTool/WindowsFormsApplication1.exe.
----------------------------------------
System.Windows.Forms
Assembly-Version: 4.0.0.0.
Win32-Version: 4.0.30319.1 built by: RTMRel.
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll.
----------------------------------------
System.Drawing
Assembly-Version: 4.0.0.0.
Win32-Version: 4.0.30319.1 built by: RTMRel.
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll.
----------------------------------------
System
Assembly-Version: 4.0.0.0.
Win32-Version: 4.0.30319.1 built by: RTMRel.
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll.
----------------------------------------
System.Windows.Forms.resources
Assembly-Version: 4.0.0.0.
Win32-Version: 4.0.30319.1 built by: RTMRel.
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms.resources/v4.0_4.0.0.0_de_b77a5c561934e089/System.Windows.Forms.resources.dll.
----------------------------------------
mscorlib.resources
Assembly-Version: 4.0.0.0.
Win32-Version: 4.0.30319.1 (RTMRel.030319-0100).
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/mscorlib.resources/v4.0_4.0.0.0_de_b77a5c561934e089/mscorlib.resources.dll.
----------------------------------------
So basically it says: "System.Data.SQLite.dll" or a dependency was not found.
The file is present in the application directory. Here's a file listing:
If you are referencing the DLL stored in System.Data.SQLite.dll stored in the GAC on your development machine from your C# project and that DLL does not exist on the test client you would get that message. In that case you either need to install SQLlite on the test machine (thereby placing the DLL in the GAC), or change the reference in your project to point at the local DLL instaid.
- try referencing a version outside the gac
- did you provide the right version (ie. 32 vs 64 bit)?
I had this problem as well and I think the first point fixed it. The machine you deploy it on doesn't have it in the gac obviously, and if you reference that version, it won't be found in the other places. At least that's the experience I had.
You need to give us more details about the exception. In the mean time, try adding the following to your app.config:
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite"/>
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite"/>
</DbProviderFactories>
</system.data>
I have the same problem. Here is what I did and found: I hooked into the AppDomain's AssemblyLoad event and traced all the assemblies that got loaded. I had added a reference to a class in System.Data.SQLite.dll to force loading before it was used by Fluent NHibernate. Lo and behold, SQLite was loaded from the GAC. No idea how it got there because I just downloaded the ZIP file of the .Net provider.
This is the reason why System.Data.SQLite.dll is copied local in the project (Project A) that directly references it, but not in projects that reference project A. For them, copying is not necessary because the file resides in the GAC. In my specific case, the NHibernate.Driver.SQLite20Driver would attempt to load the System.Data.SQLite assembly but for whatever reasons it failed to do so. Maybe it truly expects the assembly to be placed in the output folder, but then again I see AssemblyResolve attempts for that DLL, which should mean that it uses standard .Net methods to load the assembly.
In any case, the solution was to include and hook this AssemblyResolve handler in my data access DLL:
Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
if (args.Name == "System.Data.SQLite")
return typeof (CollationSequence).Assembly;
else
return null;
}
Hope this helps, Christoph
For people that installing ADO.NET SQLite Provider on client machine is out of the option: Please download the Microsoft Visual C++ 2010 Redistributable Package (x86) for 32bit and Microsoft Visual C++ 2010 Redistributable Package (x64) for 64bit windows and install them on client machines. That solved the problem for me.
You can use DEPENDS.EXE
to find DLLs
which are heeded to your System.Data.SQLite.dll
library.
In my case System.Data.SQLite.dll
did not want to load without msvcr100.dll
(C Runtime Library for native code). Adding it to the application directory solved the problem.
Note: C Runtime Library is platform dependent!
精彩评论