You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Visual Studio 2017 UWP项目中无法添加Microsoft.Data.Sqlite引用的解决方法

解决UWP项目中无法引用Microsoft.Data.Sqlite的问题

Hey there, let's tackle this issue step by step—since you're working with UWP in VS2017, there are a few specific checks and fixes to get Microsoft.Data.Sqlite working properly.

First: Clean Up Conflicting Packages

You mentioned installing multiple SQLite-related packages, and some of them might be incompatible with UWP:

  • Uninstall System.Data.SQLite immediately. This package is built for traditional .NET Framework apps, not UWP, and it will clash with Microsoft.Data.Sqlite.
  • Keep Microsoft.Data.Sqlite, sqlite-net, and sqlite-net-pcl—these are compatible with UWP, but make sure you're using versions that work with VS2017's supported frameworks. For Microsoft.Data.Sqlite, stick to versions 3.1.x or earlier (newer versions require .NET Core 3.1+, which isn't fully supported in VS2017 for UWP).

Verify Project Target Version

UWP requires a minimum Windows 10 version to support Microsoft.Data.Sqlite:

  1. Right-click your UWP project → Properties
  2. Go to the Application tab
  3. Ensure your Target version is at least Windows 10 Anniversary Update (10.0; Build 14393) and your Minimum version is no lower than that (or a compatible older version like 10586, but 14393 is safer).

Fix NuGet Installation & Cache Issues

Sometimes NuGet doesn't properly add references even after installation. Try these steps:

  • Right-click your project → Clean
  • Right-click your project → Rebuild
  • Close Visual Studio entirely, then delete the bin and obj folders in your project directory
  • Reopen VS, right-click your project → Manage NuGet Packages, and re-install Microsoft.Data.Sqlite (make sure to pick the compatible version mentioned earlier)

Add the Using Statement & Test with Valid Code

Once the above steps are done, you should be able to add the using statement in MainPage.xaml.cs. Also, remember that UWP restricts file access—you can't use arbitrary file paths for your SQLite database. Use the app's local storage instead:

using Microsoft.Data.Sqlite;
using Windows.Storage;
using System.IO;

private void LoadDatabaseData()
{
    // Get the path to your database in the app's local folder
    string dbFilePath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "your_database_name.db");

    // Create and open the connection
    using (SqliteConnection connection = new SqliteConnection($"Data Source={dbFilePath}"))
    {
        connection.Open();

        // Example query
        SqliteCommand command = connection.CreateCommand();
        command.CommandText = "SELECT * FROM YourTableName";

        using (SqliteDataReader reader = command.ExecuteReader())
        {
            while (reader.Read())
            {
                // Read data from the reader (adjust based on your table schema)
                int id = reader.GetInt32(0);
                string name = reader.GetString(1);
                // Do something with the data, like update UI elements
            }
        }
    }
}

Final Checks

  • Double-check that Microsoft.Data.Sqlite appears under References in your Solution Explorer (expand the project node to see this)
  • If you still get errors, try updating your NuGet Package Manager in VS2017 (go to Tools → Extensions and Updates to check for updates)

内容的提问来源于stack exchange,提问作者CorentinMerit

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:18:15