Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/frontend/config/sidebar/integrations.topics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,24 @@ export const integrationTopics: StarlightSidebarTopicsUserConfig = {
},
],
},
{ label: 'SQLite', slug: 'integrations/databases/sqlite' },
{
label: 'SQLite',
collapsed: true,
items: [
{
label: 'Get started',
slug: 'integrations/databases/sqlite/sqlite-get-started',
},
{
label: 'Hosting integration (AppHost)',
slug: 'integrations/databases/sqlite/sqlite-host',
},
{
label: 'Client integration (Your app)',
slug: 'integrations/databases/sqlite/sqlite-client',
},
],
},
{ label: 'SurrealDB', slug: 'integrations/databases/surrealdb' },
],
},
Expand Down
159 changes: 0 additions & 159 deletions src/frontend/src/content/docs/integrations/databases/sqlite.mdx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
---
title: SQLite Client integration reference
description: Learn how to use the Aspire SQLite Client integration to query SQLite databases from your Aspire projects.
next: false
---

import { Aside } from '@astrojs/starlight/components';
import { Badge } from '@astrojs/starlight/components';
import InstallPackage from '@components/InstallPackage.astro';
import InstallDotNetPackage from '@components/InstallDotNetPackage.astro';
import { Image } from 'astro:assets';
import sqliteIcon from '@assets/icons/sqlite-icon.png';

<Badge text="⭐ Community Toolkit" variant="tip" size="large" />

<Image
src={sqliteIcon}
alt="SQLite logo"
width={100}
height={100}
class:list={'float-inline-left icon'}
data-zoom-off
/>

To get started with the Aspire SQLite integrations, follow the [Get started with SQLite integrations](../sqlite-get-started/) guide.

This article includes full details about the Aspire SQLite Client integration, which allows you to connect to and interact with SQLite databases from your Aspire consuming projects.

## Installation

To get started with the Aspire SQLite client integration, install the [📦 CommunityToolkit.Aspire.Microsoft.Data.Sqlite](https://www.nuget.org/packages/CommunityToolkit.Aspire.Microsoft.Data.Sqlite) NuGet package in the client-consuming project, that is, the project for the application that uses the SQLite client. The SQLite client integration registers a [`SqliteConnection`](https://learn.microsoft.com/dotnet/api/microsoft.data.sqlite.sqliteconnection) instance that you can use to interact with SQLite.

<InstallDotNetPackage packageName="CommunityToolkit.Aspire.Microsoft.Data.Sqlite" />

## Add SQLite client

In the `Program.cs` file of your client-consuming project, call the `AddSqliteConnection` extension method to register a `SqliteConnection` for use via the dependency injection container. The method takes a connection name parameter.

```csharp title="C# — Program.cs"
builder.AddSqliteConnection(connectionName: "sqlite");
```

<Aside type="tip">
The `connectionName` parameter must match the name used when adding the SQLite resource in the AppHost project. For more information, see [Add SQLite resource](../sqlite-host/#add-sqlite-resource).
</Aside>

After adding `SqliteConnection` to the builder, you can get the `SqliteConnection` instance using dependency injection. For example, to retrieve your connection object from an example service define it as a constructor parameter:

```csharp title="C# — ExampleService.cs"
public class ExampleService(SqliteConnection connection)
{
// Use connection...
}
```

For more information on dependency injection, see [.NET dependency injection](https://learn.microsoft.com/dotnet/core/extensions/dependency-injection).

## Add keyed SQLite client

There might be situations where you want to register multiple `SqliteConnection` instances with different connection names. To register keyed SQLite clients, call the `AddKeyedSqliteConnection` method:

```csharp title="C# — Program.cs"
builder.AddKeyedSqliteConnection(name: "chat");
builder.AddKeyedSqliteConnection(name: "queue");
```

<Aside type="caution">
When using keyed services, it's expected that your SQLite resource configured two named databases, one for the `chat` and one for the `queue`.
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sentence "it's expected that your SQLite resource configured two named databases" is grammatically awkward. It should clarify that the AppHost project should have configured two resources.

Suggested change
When using keyed services, it's expected that your SQLite resource configured two named databases, one for the `chat` and one for the `queue`.
When using keyed services, your AppHost project is expected to configure two SQLite resources (or named databases), one for `chat` and one for `queue`.

Copilot uses AI. Check for mistakes.
</Aside>

Then you can retrieve the `SqliteConnection` instances using dependency injection:

```csharp title="C# — ExampleService.cs"
public class ExampleService(
[FromKeyedServices("chat")] SqliteConnection chatConnection,
[FromKeyedServices("queue")] SqliteConnection queueConnection)
{
// Use connections...
}
```

For more information on keyed services, see [.NET dependency injection: Keyed services](https://learn.microsoft.com/dotnet/core/extensions/dependency-injection#keyed-services).

## Properties of the SQLite resources

When you use the `WithReference` method to pass a SQLite database resource from the AppHost project to a consuming client project, Aspire exposes the data source as an environment variable with a standardized naming convention:

| Property Name | Description | Environment Variable Format |
|---------------|-------------|----------------------------|
| `DataSource` | The data source path containing the database file path. | `C:\{Path}\{Databasefile}.db` |

<Aside type="note">
Aspire exposes the data source as an environment variable named `{ResourceName}_DATASOURCE`. For instance, a resource called `sqlite` would have its data source string available as `SQLITE_DATASOURCE`.
Comment on lines +86 to +93
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The table in this section describes only the DataSource property, but the documentation in sqlite-get-started.mdx (line 158) and sqlite-host.mdx (line 123) references environment variables with different naming conventions ({ResourceName}_DATASOURCE vs ConnectionStrings__sqlite). The documentation should clarify all environment variables that are injected by WithReference, not just DataSource, to provide complete information for non-.NET applications.

Suggested change
When you use the `WithReference` method to pass a SQLite database resource from the AppHost project to a consuming client project, Aspire exposes the data source as an environment variable with a standardized naming convention:
| Property Name | Description | Environment Variable Format |
|---------------|-------------|----------------------------|
| `DataSource` | The data source path containing the database file path. | `C:\{Path}\{Databasefile}.db` |
<Aside type="note">
Aspire exposes the data source as an environment variable named `{ResourceName}_DATASOURCE`. For instance, a resource called `sqlite` would have its data source string available as `SQLITE_DATASOURCE`.
When you use the `WithReference` method to pass a SQLite database resource from the AppHost project to a consuming client project, Aspire exposes the SQLite connection information via environment variables with standardized naming conventions:
| Property Name | Description | Environment Variable |
|---------------|-------------|----------------------|
| `DataSource` | The SQLite connection string or data source path containing the database file path (for example, `Data Source=C:\{Path}\{Databasefile}.db`). | - `{RESOURCE_NAME}_DATASOURCE`<br />- `ConnectionStrings__{ResourceName}` |
<Aside type="note">
Aspire exposes the same `DataSource` value under multiple environment variable names:
<ul>
<li><code>{RESOURCE_NAME}_DATASOURCE</code> &mdash; a generic environment variable that can be used by any consumer (for example, a resource called <code>sqlite</code> would have <code>SQLITE_DATASOURCE</code>).</li>
<li><code>ConnectionStrings__{ResourceName}</code> &mdash; the conventional .NET configuration key for the connection string (for example, <code>ConnectionStrings__sqlite</code>).</li>
</ul>
Non-.NET applications will typically read <code>{RESOURCE_NAME}_DATASOURCE</code> directly, while .NET applications can use the <code>ConnectionStrings</code> configuration section.

Copilot uses AI. Check for mistakes.
</Aside>

## Configuration

The SQLite client integration provides multiple options to configure the connection based on the requirements and conventions of your project.

### Use a connection string

When using a connection string from the `ConnectionStrings` configuration section, you can provide the name of the connection string when calling the `AddSqliteConnection` method:

```csharp title="C# — Program.cs"
builder.AddSqliteConnection("sqlite");
```

Then the connection string will be retrieved from the `ConnectionStrings` configuration section:

```json title="JSON — appsettings.json"
{
"ConnectionStrings": {
"sqlite": "Data Source=C:\\Database\\Location\\my-database.db"
}
}
```

For more information on how to format this connection string, see [Microsoft.Data.Sqlite connection strings](https://learn.microsoft.com/dotnet/standard/data/sqlite/connection-strings).

### Use configuration providers

The SQLite client integration supports `Microsoft.Extensions.Configuration`. It loads the settings from configuration using the `Aspire:Sqlite:Client` key. Example `appsettings.json` that configures some of the options:

```json title="JSON — appsettings.json"
{
"Aspire": {
"Sqlite": {
"Client": {
"ConnectionString": "Data Source=C:\\Database\\Location\\my-database.db",
"DisableHealthCheck": true
}
}
}
}
```

### Use inline delegates

You can also pass the `Action<SqliteConnectionSettings>` delegate to set up some or all the options inline:

```csharp title="C# — Program.cs"
builder.AddSqliteConnection(
"sqlite",
static settings => settings.DisableHealthCheck = true);
```

## Client integration health checks

By default, Aspire integrations enable [health checks](/fundamentals/health-checks/) for all services. For more information, see [Aspire integrations overview](/integrations/overview/).

The Aspire SQLite integration:

- Adds the health check when `SqliteConnectionSettings.DisableHealthCheck` is `false`, which attempts to open a connection to the SQLite database.
- Integrates with the `/health` HTTP endpoint, which specifies all registered health checks must pass for app to be considered ready to accept traffic.

## Observability and telemetry

Aspire integrations automatically set up Logging, Tracing, and Metrics configurations, which are sometimes known as *the pillars of observability*. Depending on the backing service, some integrations may only support some of these features. For example, some integrations support logging and tracing, but not metrics. Telemetry features can also be disabled using the techniques presented in the [Configuration](#configuration) section.

### Logging

The Aspire SQLite integration uses standard .NET logging mechanisms for database operations.

### Tracing

The Aspire SQLite integration will emit tracing activities for database operations using OpenTelemetry when configured.

### Metrics

The Aspire SQLite integration currently has limited metrics support compared to other database integrations due to the nature of SQLite as an embedded database engine.
Loading
Loading