3

I am trying to add SQLite with ADO.Net, and I am really struggling with it.

This is the packages I have installed:

  • Stub.System.Data.SQLite.Core.NetFramework 1.0.115
  • System.Data.SQLite 1.0.115
  • System.Data.SQLite.Core 1.0.115
  • System.Data.SQLite.EF6 1.0.115
  • System.Data.SQLite.Linq 1.0.115
  • EntityFramework 6.4.4

    I have created the db using dbBrowser and placed it within the app.
    Whatever I do, I just can't seem to get the connection:

    enter image description here

    I have look at this, however it is 6 years old.
    I have also tried this, but without success.
    On the system.data.sqlite website, it is mentioned: "The setup packages, which contain the Design-Time Components for Visual Studio are no longer officially supported". So how?

What am I missing? How do we use sqlite with ado.net in vs2019?

6
  • 1
    install DDEX provider Commented Oct 7, 2021 at 13:41
  • "The setup packages, which contain the Design-Time Components for Visual Studio are no longer officially supported" meaning "Download the latest sqlite-netFx46-setup-bundle-x86-2015-1.0.xxx.0.exe" is no longer valid. I believe this was due to a change in vs2019 in August (?) Commented Oct 7, 2021 at 15:21
  • 1
    install this extension: vsixgallery.com/extension/41521019-e4c7-480c-8ea8-fc4a2c6f50aa Commented Oct 7, 2021 at 17:26
  • You were correct. The mistake I was doing was to install the 64-bit version, while the 32 is required for visual studio. Thanks MagicAndre. Commented Oct 19, 2021 at 19:42
  • 1
    ok, post an answer what you did in detail to help others Commented Oct 20, 2021 at 9:35

2 Answers 2

3

Installing Sqlite with ado.net on a WPF .NET Framework project, is relatively easy if you know the steps. Thanks to MagicAndre for providing guidance. Here we go:

1 - Install the toolbox from here. This is straight forward.

2 - Install GAC from here. Now here is where I was failing. I was installing the 64-bit package only, while the 32 is needed for the GAC. So download and install:

  • sqlite-netFx46-setup-bundle-x86-2015-1.0.115.0.exe
  • sqlite-netFx46-setup-bundle-x64-2015-1.0.115.0.exe

    When installing the 32-bit package, be careful to check as per below image:

    enter image description here

3 - If you haven’t created your db, download DB Browser from here. Create your db, place a copy within your project, and include it. You can set the build action to content if you are going to distribute the app later.

4 - Create a solution in visual studio, and nugget install: System.Data.SQLite: This will auto install the other 4 packages as well as EntityFramework

5 - In visual studio, go to your server explorer, right click Data connections, add connection

Change your data source to: SQLite Provider (Simple for EF6 by ErikEJ) (SQLite Provider (Simple for EF6 by ErikEJ))

A new window will open The connectionString line at the top would be in this format:
Data source="C:\Users...\Documents\Visual Studio 2019\Projects\sqlite\sqlite\demo.db";Version=3;
Data source=path;Version=3;

enter image description here

Click ok and the connection will appear in server explorer.

6 - ADO.NET:
Right click solution, add, add new item. Go to Data and select ado.net EF Designer from database (database first) and your connection should appear:

enter image description here

Click next, select all tables required, and click finish. Your edmx file will then be prepared and opened.

7 - Within your app.config entityFramework section, the following lines should be there:

<providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
      <provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
      <provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
    </providers>

Below should be a system.data section as:

<system.data>
    <DbProviderFactories>
      <remove invariant="System.Data.SQLite.EF6" />
      <add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" />
      <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>

Finally, If you are going to use Foreign keys, add:

Foreign Key Constraints=On; 

between the path and the version of the connection string, in the app.config file.

I think that's about it to get started. Good luck.

Sign up to request clarification or add additional context in comments.

Comments

1

I have a .net6 application running the latest version of the 'sqlite-net-pcl' NuGet, but had issues running the same NuGet in 4.8 framework.

I found out the the only version that worked for me was 'sqlite-net-pcl' version 1.7.335 then had to update the 'SQLitePCLRaw' depencies to 2.0.4

my SQLite NuGet's

1 Comment

This combination works here too: 4.8 framework + sqlite-net-pcl 1.7.335 + update SQLitePCLRaw depencies to 2.0.4. Tks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.