Skip to content

Commit 544193f

Browse files
Update SQLite topic for freshness, seo and copilot (#5851)
1 parent fcbafbf commit 544193f

1 file changed

Lines changed: 53 additions & 7 deletions

File tree

hub/apps/develop/data-access/sqlite-data-access.md

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,52 @@
11
---
22
title: Use a SQLite database in a Windows app
33
description: Learn how to use a SQLite database in a Windows app to store and retrieve data in a lightweight database on the user's device.
4-
ms.date: 08/01/2024
4+
ms.date: 09/25/2025
55
ms.topic: how-to
6-
keywords: windows 10, windows 11, windows app sdk, SQLite, database
6+
keywords: windows 10, windows 11, windows app sdk, winui, SQLite, database
77
ms.localizationpriority: medium
8+
ms.custom: copilot-scenario-highlight
89
#customer intent: As a Windows developer, I want to learn how to use a SQLite database in a Windows app to store and retrieve data in a lightweight database on the user's device.
910
---
1011

1112
# Use a SQLite database in a Windows app
1213

13-
You can use SQLite to store and retrieve data in a lightweight database on the user's device. This guide shows you how to do it in your Windows App SDK apps.
14+
[SQLite](https://sqlite.org/index.html) provides a reliable, lightweight database solution for storing data locally in Windows apps. Unlike traditional database systems that require separate server installations and complex configurations, SQLite runs entirely within your application process and stores data in a single file on the user's device.
1415

15-
## Some benefits of using SQLite for local storage
16+
This tutorial shows you how to integrate SQLite into your WinUI application using Microsoft's recommended data access libraries. You'll learn to set up a database, create tables, and implement basic data operations—all while following security best practices to protect against common vulnerabilities.
17+
18+
## What you'll accomplish
19+
20+
In this tutorial, you'll learn how to:
21+
22+
- Configure your Windows app to use SQLite with the Microsoft.Data.SQLite library
23+
- Create and initialize a local database
24+
- Implement secure data insertion and retrieval methods
25+
- Build a simple user interface to interact with your data
26+
27+
## Prerequisites
28+
29+
To complete this tutorial, you need:
30+
31+
- Visual Studio with Windows App SDK development workload
32+
- Basic familiarity with C# and XAML
33+
- Understanding of fundamental database concepts
34+
35+
## Key improvements this approach offers
36+
37+
Using SQLite for local data storage in your Windows app offers several advantages:
38+
39+
- Simplified deployment: No separate database server installation required
40+
- Enhanced security: Data stays local on the user's device
41+
- Improved performance: Direct file access eliminates network latency
42+
- Reduced complexity: Single-file database simplifies backup and migration
43+
44+
The techniques you'll learn apply to any Windows app that needs to store structured data locally, from simple settings storage to complex data management scenarios.
45+
46+
> [!TIP]
47+
> You can use AI assistance to help [avoid SQL injection attacks in SQLite](#avoid-sql-injection-attacks).
48+
49+
## Benefits of SQLite for local storage
1650

1751
:heavy_check_mark: SQLite is lightweight and self-contained. It's a code library without any other dependencies. There's nothing to configure.
1852

@@ -40,7 +74,7 @@ The [Microsoft.Data.Sqlite](/dotnet/api/microsoft.data.sqlite) library implement
4074

4175
The rest of this guide helps you to use this library.
4276

43-
## Set up your solution to use the Microsoft.Data.SQlite library
77+
## Set up your solution to use the Microsoft.Data.SQLite library
4478

4579
We'll start with a basic Windows App SDK project, and then install the SQLite NuGet package.
4680

@@ -82,8 +116,8 @@ We'll do these things:
82116

83117
Open the `DataAccess` class in your project and make that class static.
84118

85-
>[!NOTE]
86-
>While our example will place data access code in a static class, this is a design choice and is completely optional.
119+
> [!NOTE]
120+
> While the example will put your data access code in a static class, this is a design choice and is completely optional.
87121
88122
```csharp
89123
public static class DataAccess
@@ -248,6 +282,18 @@ public MainWindow()
248282

249283
That's it. Explore the [Microsoft.Data.Sqlite](/dotnet/api/microsoft.data.sqlite) to see what other things you can do with your SQLite database. Check out the links below to learn about other ways to use data in your Windows apps.
250284

285+
## Avoid SQL injection attacks
286+
287+
The code in this example uses parameterized queries to prevent SQL injection attacks. Never concatenate user input into a SQL query string. Always use parameters. You can ask Copilot for more tips on avoiding SQL injection attacks.
288+
289+
The following text shows an example prompt for Copilot:
290+
291+
```copilot-prompt
292+
Can you provide some best practices to avoid SQL injection attacks when writing SQLite queries in C# code?
293+
```
294+
295+
Copilot is powered by AI, so surprises and mistakes are possible. For more information, see [Copilot FAQs](https://aka.ms/copilot-general-use-faqs).
296+
251297
## Related content
252298

253299
### Connect your app directly to a SQL Server database

0 commit comments

Comments
 (0)