tags:

views:

49

answers:

2

I am trying to access my databases in C#. The databases are SQLite and I am trying to access it like so:

string CurrentDatabase = Path.FullName + "\\stock.sqlite";

SQLiteBase db = new SQLiteBase(CurrentDatabase);

I am using a SQLite DLL I found here to access the database:

http://www.codeproject.com/KB/database/cs_sqlitewrapper.aspx

But I get this error:

Unable to load DLL 'sqlite3': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

I think I know what's wrong, I dont have the sqlite3 DLL anywhere on my system... but I would like this application to be portable so I cannot expect users to already have this DLL installed. I have read about loading a DLL from another application which has already got this DLL somewhere, Firefox is a good example. It's installed on all of my companies machines and if I could some how load the sqlite3 DLL from the Firefox Program Files directory into my application it should work perfectly, no? If that's really the solution I'll need help actually loading the DLL, as I don't know how to do that.

Thanks.

+1  A: 

Copy the sqlite3.dll into the same directory where your DLL wrapper is and supply that as part of the distributable of your application when done, in that way there'll be no nonsense associated with dll versioning mismatches.. you can download the latest version from http://sqlite.org

tommieb75
Just another quick Q: if I add some DLLs as references by going to Project -> Add Reference and then browsing to it, when compiled would the resulting .exe have that DLL in it or would I need to maintain the file structure?
Kratz
@Kratz: the DLL will be bundled and be part of the application, not combined into the EXE physically, more of you will have one file which would be EXE, and its supporting DLL's would be in the same folder as where the .EXE is residing in.
tommieb75
That's good, thanks. Also when I try and add the sqlite3.dll file as a reference I get this error: `A reference to 'C:\Users\Username\Documents\Visual Studio 2008\Projects\Stock Updating\sqlite3.dll' could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component.`
Kratz
It's probably a native DLL. SQLite comes in various flavours; some of them are mixed assemblies containing both native and managed code, whereas others require the native DLL to be present in the bin directory. It's pretty confusing if you pick the wrong version, plus you can end up with bitness problems if you build using Any CPU (as the managed app will run in whatever bitness your OS has, but the native dll maybe be compiled to target something else).
Mark Simpson
+1  A: 

I recommend using System.Data.SQLite, which is an ADO.NET provider for SQLite. Then you can program with the ADO.NET API. Its DLL includes sqlite3.dll, so you don't have to include it.

Stephen Cleary