Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use SQLite in Visual Studio 2017?

I'm using Visual Studio 2017, in UWP project. I installed SQLite Compact Toolbox from NuGet package like this:

  • Microsoft.Data.sqlite / sqlite-net / sqlite-net-pcl / System.Data.SQLite

After that, I still can't add using Microsoft.Data.Sqlite in MainPage.xaml.cs to read values in my table and make a query.

How can I be able to add using Microsoft.Data.Sqlite?

like image 389
CorentinMerit Avatar asked Jan 25 '18 09:01

CorentinMerit


People also ask

Does Visual Studio support SQLite?

The SQL Server Compact & SQLite Toolbox adds several features to help your SQL Server Compact and SQLite development efforts: Explore! Connect to SQL Server Compact 4.0, 3.5, SQL Server and SQLite database files in Visual Studio 2017 and later.

Can I use SQLite with C#?

SQLite is open source file system database. Unlike SQL Server, this doesn't require any Service to interact with the database but the real problem occurs, when we try to interact with SQLite DB in C#. There is no proper Entity Framework support available, as of now. Thus, we are compelled to use inline queries.

How do I run a SQLite application in Visual Studio?

Open Visual Studio, select new project, and, in Visual C#, select “Console Application” and provide the name as SQLiteDemo. Click OK. To connect SQLite with C#, we need drivers. Install all required SQLite resources from the NuGet package, as pictured in Figure 1. Figure 1: .NET Console application

How to add SQLite/SQL Server Compact Toolbox in Visual Studio 2017?

Add SQLite/SQL Server Compact Toolbox from In Visual Studio 2017 Community. Goto Tools - Extensions and Updates - click Online. Search for Sqlite. You should see Sqlite compact toolbox. Click download . Restart visual studio.

What version of SQLite is included in Visual Studio 2017?

In Microsoft Visual Studio 2017, I have included the sqlite3.lib file and directories and copied the sqlite3.dll to the project directory. I should note the included sqlite3.lib is the x86 version.

What is a a SQLite database?

A SQLite database is integrated with the application that accesses the database. The SQLite database file format is cross-platform and can be copied between 32-bit and 64-bit file systems. Due to the serverless architecture, developers don’t need to install SQLite before using it.


3 Answers

Add SQLite/SQL Server Compact Toolbox from In Visual Studio 2017 Community. Goto Tools - Extensions and Updates - click Online. Search for Sqlite. You should see Sqlite compact toolbox. Click download . Restart visual studio.

like image 145
David Morrow Avatar answered Oct 18 '22 20:10

David Morrow


Try using

using System.Data.SQLite;

Read more here https://system.data.sqlite.org/index.html/doc/trunk/www/index.wiki

like image 1
J.B. Avatar answered Oct 18 '22 21:10

J.B.


how to use sqlite in visual studio 2017

I'd recommend you to follow this latest tutorial to use a SQLite database in a UWP app.

And i can't add using Microsoft.Data.Sqlite

If you installed the Microsoft.Data.Sqlite Nuget package, but cannot reference the Microsoft.Data.Sqlite namespace, you may need to check the versions of UWP app,package and Microsoft.NETCore.UniversalWindowsPlatform. As the article mentioned,if the minimum version of your project does not target the Fall Creators Update, you need to upgrade Microsoft.NETCore.UniversalWindowsPlatform package to 5.2.2 (or higher) and install version 1.1.1 (or lower) of Microsoft.Data.Sqlite package. Details please check The minimum version of your project does not target the Fall Creators Update section.

There're many Nuget packages for SQLite, some of them are older with long time no updating. Install many packages at a same time may lead conflicts.Try un-install them all and just following above tutorial.

There is a sample which use the old SQLite.Net-PCL package you could also reference if you do want to use other packages.

like image 1
Sunteen Wu Avatar answered Oct 18 '22 20:10

Sunteen Wu