How to add SQLite (SQLite.NET) to my C# project

12,406

You dropped the DLL into your .\Dev\DataFeed folder - and did you add a reference to that DLL to your project?? The error you get seems to indicate you don't have a reference set up to that DLL - this won't happen just by itself, you need to manually add a reference to an external DLL if you want to use stuff from it.

Share:
12,406

Related videos on Youtube

Kiril
Author by

Kiril

CEO and Co-Founder of ST6.io E-mail: click to reveal e-mail

Updated on June 04, 2022

Comments

  • Kiril
    Kiril almost 2 years

    I followed the instructions in the documentation:

    Scenario 1: Version Independent (does not use the Global Assembly Cache)

    This method allows you to drop any new version of the System.Data.SQLite.DLL into your application's folder and use it without any code modifications or recompiling. Add the following code to your app.config file:

    <configuration>
      <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>
    </configuration>
    

    My app.config file now looks like this:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <configSections>
            <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
                <section name="DataFeed.DataFeedSettings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
            </sectionGroup>
        </configSections>
        <userSettings>
            <DataFeed.DataFeedSettings>
                <setting name="eodData" serializeAs="String">
                    <value>False</value>
                </setting>
            </DataFeed.DataFeedSettings>
        </userSettings>
        <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>
    </configuration>
    

    My project is called "DataFeed":

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Data.SQLite; //<-- Causes compiler error
    
    namespace DataFeed
    {
        class Program
        {
            static void Main(string[] args)
            {
            }
        }
    }
    

    The error I get is:

    .\dev\DataFeed\Program.cs(5,19): error CS0234: The type or namespace name 'SQLite' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)

    I'm prefer not to use the GAC so I simply dropped the System.Data.SQLite.dll into my .\dev\DataFeed\ folder. I thought that all I needed to do is add the DLL to the project folder as it was mentioned in the documentation, but I can't use the library. Any hints on how to actually make this work?

  • marc_s
    marc_s about 14 years
    @Lirik: sometimes it's the simple stuff that gets in your way and you can't see it yourself :-) Been there, experienced that....
  • Kiril
    Kiril about 14 years
    I guess it happens, especially at 1:00 in the morning :)... the brain starts thinking about sleeping and I'm still asking it to think about developing.