C# and SQLite - Part 2: Getting Your Visual Studio Project Ready for SQLite

Alright, you've made it past part 1 and now your eager to get your database on. First we have to download and install the the correct SQLite package for the version of .NET that we are using. And we have to get the 32-bit or 64-bit version of that specific .NET version. What ever version you need, the downloads are available from SQLite.org's Download page. Be sure the read that page as there is a lot of important information there that will help you decide which download is correct for you.

In part 1 I decided that i would run a 32-bit version of SQLite for maximum compatibility. My application that I'm writing will be for .NET version 4.0. So I need to get the download for .NET 4.0 32-bit. But do I want the "setup" package or the "pre-compiled binaries"? To make your application work you only need one dll file from SQLite. If you download the precompiled binaries and un-zip the file you can get there. If you want to "install" SQLite on you computer to be used in more ways then just this application you can get the setup and go that route. I've chosen to get the "pre-compiled binaries". After you download the zip file, un-zip it and locate the file called "System.Data.SQLite.dll". Then copy the file to somewhere in your Visual Studio project folder for the next step.

So now you've downloaded and copied the SQLite library for the .NET and bit version that you need. Now what? Well... we have to let our Visual Studio project know where the libraries are.

NOTE: I'm using Visual Studio Express 2013 for my project. The VS instructions that I'm about to provide may be different for different versions of VS.

Open or create your project in Visual Studio. In the main menu at the top, click "Project" then click "Add Reference" This opens a new window. In this new window click the "Browse" button. Now we have to find the dll file that you just copied. Once you've selected the "System.Data.SQLite.dll" file click the "Add" button". This will put you back at the "Reference Manager" window where you can now see the library has been added. So now just click the "OK" button.

NOTE: If you chose to install SQLite then the file will be located in either "C:\Program Files\System.Data.SQLite\<number>\bin\System.Data.SQLite.dll" or in "C:\Program Files (x86)\System.Data.SQLite\<number>\bin\". The location will depend on whether or not you are on a 32-bit or 64-bit OS and whether or not you downloaded the 32-bit or 64-bit libraries.

Now your project knows how to find the SQLite libraries. The only thing left to do is to let the C# code know that you are using it. Simple enough just add

using System.Data.SQLite;

at the top of your code with the rest of the "using" statements.

In part 3 I'll give some practical examples of using SQLite in C#.

Part 3 coming soon.