Aspire.Hosting.Azure.Sql
13.1.0
Prefix Reserved
dotnet add package Aspire.Hosting.Azure.Sql --version 13.1.0
NuGet\Install-Package Aspire.Hosting.Azure.Sql -Version 13.1.0
<PackageReference Include="Aspire.Hosting.Azure.Sql" Version="13.1.0" />
<PackageVersion Include="Aspire.Hosting.Azure.Sql" Version="13.1.0" />
<PackageReference Include="Aspire.Hosting.Azure.Sql" />
paket add Aspire.Hosting.Azure.Sql --version 13.1.0
#r "nuget: Aspire.Hosting.Azure.Sql, 13.1.0"
#:package Aspire.Hosting.Azure.Sql@13.1.0
#addin nuget:?package=Aspire.Hosting.Azure.Sql&version=13.1.0
#tool nuget:?package=Aspire.Hosting.Azure.Sql&version=13.1.0
Aspire.Hosting.Azure.Sql library
Provides extension methods and resource definitions for an Aspire AppHost to configure Azure SQL DB.
Getting started
Prerequisites
- Azure subscription - create one for free
Install the package
Install the Aspire Azure SQL Server Hosting library with NuGet:
dotnet add package Aspire.Hosting.Azure.Sql
Configure Azure Provisioning for local development
Adding Azure resources to the Aspire application model will automatically enable development-time provisioning for Azure resources so that you don't need to configure them manually. Provisioning requires a number of settings to be available via .NET configuration. Set these values in user secrets in order to allow resources to be configured automatically.
{
"Azure": {
"SubscriptionId": "<your subscription id>",
"ResourceGroupPrefix": "<prefix for the resource group>",
"Location": "<azure location>"
}
}
NOTE: Developers must have Owner access to the target subscription so that role assignments can be configured for the provisioned resources.
Usage example
In the AppHost.cs file of AppHost, register a SqlServer database and consume the connection using the following methods:
var sql = builder.AddAzureSqlServer("sql")
.AddDatabase("sqldata");
var myService = builder.AddProject<Projects.MyService>()
.WithReference(sql);
The WithReference method configures a connection in the MyService project named sqldata. In the Program.cs file of MyService, the sql connection can be consumed using the client library Aspire.Microsoft.Data.SqlClient:
builder.AddSqlServerClient("sqldata");
Connection Properties
When you reference Azure SQL Server resources using WithReference, the following connection properties are made available to the consuming project:
Azure SQL Server resource
The Azure SQL Server resource exposes the following connection properties:
| Property Name | Description |
|---|---|
Host |
The fully qualified domain name of the Azure SQL Server |
Port |
The SQL Server port (1433 for Azure) |
Uri |
The connection URI, with the format mssql://{Host}:{Port} |
JdbcConnectionString |
JDBC connection string with the format jdbc:sqlserver://{Host}:{Port};encrypt=true;trustServerCertificate=false; |
Azure SQL database resource
The Azure SQL database resource inherits all properties from its parent Azure SQL Server resource and adds:
| Property Name | Description |
|---|---|
DatabaseName |
The name of the database |
Uri |
The connection URI, with the format mssql://{Host}:{Port}/{DatabaseName} |
JdbcConnectionString |
JDBC connection string with the format jdbc:sqlserver://{Host}:{Port};database={DatabaseName};encrypt=true;trustServerCertificate=false; |
Aspire exposes each property as an environment variable named [RESOURCE]_[PROPERTY]. For instance, the Uri property of a resource called db1 becomes DB1_URI.
The client should add a valid authentication property for the JDBC connection string like authentication=ActiveDirectoryDefault or authentication=ActiveDirectoryManagedIdentity.
Azure SQL DB defaults
Unless otherwise specified, the Azure SQL DB created will be a 2vCores General Purpose Serverless database (GP_S_Gen5_2) with the free offer enabled.
Read more about the free offer here: Deploy Azure SQL Database for free
The free offer is configured so that when the maximum usage limit is reached, the database is stopped to avoid incurring in unexpected costs.
If you don't want to use the free offer and instead deploy the database use the default sku set by Azure, use the WithAzureDefaultSku method:
var sql = builder.AddAzureSqlServer("sql")
.AddDatabase("db", "my-db-name")
.WithAzureDefaultSku();
Setting a specific SKU
If you want to manually define what SKU must be used when deploying the Azure SQL DB resource, use the ConfigureInfrastructure method:
var sqlSrv = builder.AddAzureSqlServer("sqlsrv")
.ConfigureInfrastructure(infra => {
var azureResources = infra.GetProvisionableResources();
var azureDb = azureResources.OfType<SqlDatabase>().Single();
azureDb.Sku = new SqlSku() { Name = "HS_Gen5_2" };
})
.AddDatabase("sqldb", "DatabaseName");
.RunAsContainer();
Additional documentation
- https://learn.microsoft.com/dotnet/framework/data/adonet/sql/
- https://learn.microsoft.com/dotnet/api/system.data.sqlclient.sqlconnection
- https://github.com/dotnet/aspire/tree/main/src/Components/README.md
Feedback & contributing
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Aspire.Hosting.Azure (>= 13.1.0)
- Aspire.Hosting.SqlServer (>= 13.1.0)
- AspNetCore.HealthChecks.SqlServer (>= 9.0.0)
- AspNetCore.HealthChecks.Uris (>= 9.0.0)
- Azure.Core (>= 1.50.0)
- Azure.Identity (>= 1.17.0)
- Azure.Provisioning (>= 1.4.0)
- Azure.Provisioning.KeyVault (>= 1.1.0)
- Azure.Provisioning.Sql (>= 1.1.0)
- Azure.ResourceManager.Authorization (>= 1.1.6)
- Azure.ResourceManager.KeyVault (>= 1.3.3)
- Azure.ResourceManager.Resources (>= 1.11.1)
- Azure.Security.KeyVault.Secrets (>= 4.8.0)
- Google.Protobuf (>= 3.33.0)
- Grpc.AspNetCore (>= 2.71.0)
- Grpc.Net.ClientFactory (>= 2.71.0)
- Grpc.Tools (>= 2.72.0)
- Humanizer.Core (>= 2.14.1)
- JsonPatch.Net (>= 3.3.0)
- KubernetesClient (>= 18.0.5)
- Microsoft.Data.SqlClient (>= 6.1.2)
- Microsoft.Extensions.Caching.Memory (>= 10.0.1)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.1)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.1)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 10.0.1)
- Microsoft.Extensions.FileSystemGlobbing (>= 10.0.1)
- Microsoft.Extensions.Hosting (>= 10.0.1)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.1)
- Microsoft.Extensions.Http (>= 10.0.1)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.1)
- Microsoft.Extensions.Options (>= 10.0.1)
- Microsoft.Extensions.Primitives (>= 10.0.1)
- Newtonsoft.Json (>= 13.0.4)
- Polly.Core (>= 8.6.4)
- Semver (>= 3.0.0)
- StreamJsonRpc (>= 2.22.23)
- System.IO.Hashing (>= 9.0.10)
-
net8.0
- Aspire.Hosting.Azure (>= 13.1.0)
- Aspire.Hosting.SqlServer (>= 13.1.0)
- AspNetCore.HealthChecks.SqlServer (>= 9.0.0)
- AspNetCore.HealthChecks.Uris (>= 9.0.0)
- Azure.Core (>= 1.50.0)
- Azure.Identity (>= 1.17.0)
- Azure.Provisioning (>= 1.4.0)
- Azure.Provisioning.KeyVault (>= 1.1.0)
- Azure.Provisioning.Sql (>= 1.1.0)
- Azure.ResourceManager.Authorization (>= 1.1.6)
- Azure.ResourceManager.KeyVault (>= 1.3.3)
- Azure.ResourceManager.Resources (>= 1.11.1)
- Azure.Security.KeyVault.Secrets (>= 4.8.0)
- Google.Protobuf (>= 3.33.0)
- Grpc.AspNetCore (>= 2.71.0)
- Grpc.Net.ClientFactory (>= 2.71.0)
- Grpc.Tools (>= 2.72.0)
- Humanizer.Core (>= 2.14.1)
- JsonPatch.Net (>= 3.3.0)
- KubernetesClient (>= 18.0.5)
- Microsoft.Data.SqlClient (>= 6.1.2)
- Microsoft.Extensions.Caching.Memory (>= 8.0.1)
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.2)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 8.0.22)
- Microsoft.Extensions.FileSystemGlobbing (>= 10.0.1)
- Microsoft.Extensions.Hosting (>= 8.0.1)
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.1)
- Microsoft.Extensions.Http (>= 8.0.1)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.3)
- Microsoft.Extensions.Options (>= 8.0.2)
- Microsoft.Extensions.Primitives (>= 8.0.0)
- Newtonsoft.Json (>= 13.0.4)
- Polly.Core (>= 8.6.4)
- Semver (>= 3.0.0)
- StreamJsonRpc (>= 2.22.23)
- System.IO.Hashing (>= 9.0.10)
-
net9.0
- Aspire.Hosting.Azure (>= 13.1.0)
- Aspire.Hosting.SqlServer (>= 13.1.0)
- AspNetCore.HealthChecks.SqlServer (>= 9.0.0)
- AspNetCore.HealthChecks.Uris (>= 9.0.0)
- Azure.Core (>= 1.50.0)
- Azure.Identity (>= 1.17.0)
- Azure.Provisioning (>= 1.4.0)
- Azure.Provisioning.KeyVault (>= 1.1.0)
- Azure.Provisioning.Sql (>= 1.1.0)
- Azure.ResourceManager.Authorization (>= 1.1.6)
- Azure.ResourceManager.KeyVault (>= 1.3.3)
- Azure.ResourceManager.Resources (>= 1.11.1)
- Azure.Security.KeyVault.Secrets (>= 4.8.0)
- Google.Protobuf (>= 3.33.0)
- Grpc.AspNetCore (>= 2.71.0)
- Grpc.Net.ClientFactory (>= 2.71.0)
- Grpc.Tools (>= 2.72.0)
- Humanizer.Core (>= 2.14.1)
- JsonPatch.Net (>= 3.3.0)
- KubernetesClient (>= 18.0.5)
- Microsoft.Data.SqlClient (>= 6.1.2)
- Microsoft.Extensions.Caching.Memory (>= 9.0.11)
- Microsoft.Extensions.Configuration.Abstractions (>= 9.0.11)
- Microsoft.Extensions.Configuration.Binder (>= 9.0.11)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.11)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 9.0.11)
- Microsoft.Extensions.FileSystemGlobbing (>= 10.0.1)
- Microsoft.Extensions.Hosting (>= 9.0.11)
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.11)
- Microsoft.Extensions.Http (>= 9.0.11)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.11)
- Microsoft.Extensions.Options (>= 9.0.11)
- Microsoft.Extensions.Primitives (>= 9.0.11)
- Newtonsoft.Json (>= 13.0.4)
- Polly.Core (>= 8.6.4)
- Semver (>= 3.0.0)
- StreamJsonRpc (>= 2.22.23)
- System.IO.Hashing (>= 9.0.10)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Aspire.Hosting.Azure.Sql:
| Package | Downloads |
|---|---|
|
Extensions.Aspire.SqlServer
Extensions for SQL Server Aspire integration |
|
|
Toxic.Aspire
Contains sensible conventions and utilities for Aspire projects that are deployed to Azure. |
GitHub repositories (2)
Showing the top 2 popular GitHub repositories that depend on Aspire.Hosting.Azure.Sql:
| Repository | Stars |
|---|---|
|
rstropek/Samples
|
|
|
SSWConsulting/SSW.CleanArchitecture
SSW Clean Architecture Template
|
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 13.1.0 | 34,653 | 12/17/2025 | |
| 13.0.2 | 11,345 | 12/4/2025 | |
| 13.0.1 | 5,703 | 11/26/2025 | |
| 13.0.0 | 18,564 | 11/11/2025 | |
| 9.5.2 | 27,217 | 10/23/2025 | |
| 9.5.1 | 23,126 | 10/3/2025 | |
| 9.5.0 | 8,689 | 9/25/2025 | |
| 9.4.2 | 13,473 | 9/2/2025 | |
| 9.4.1 | 11,399 | 8/12/2025 | |
| 9.4.0 | 10,603 | 7/29/2025 | |
| 9.3.2 | 21,721 | 6/20/2025 | |
| 9.3.1 | 8,377 | 6/10/2025 | |
| 9.3.0 | 21,353 | 5/19/2025 | |
| 9.2.1 | 10,321 | 4/24/2025 | |
| 9.2.0 | 8,270 | 4/10/2025 | |
| 9.1.0 | 38,818 | 2/25/2025 | |
| 9.0.0 | 35,375 | 11/12/2024 | |
| 9.0.0-rc.1.24511.1 | 1,055 | 10/15/2024 | |
| 8.2.2 | 5,492 | 10/24/2024 | |
| 8.2.1 | 5,455 | 9/26/2024 | |
| 8.2.0 | 15,081 | 8/29/2024 | |
| 8.1.0 | 4,061 | 7/23/2024 | |
| 8.0.2 | 2,926 | 6/28/2024 | |
| 8.0.1 | 3,417 | 5/21/2024 | |
| 8.0.0 | 582 | 5/21/2024 | |
| 8.0.0-preview.7.24251.11 | 677 | 5/7/2024 | |
| 8.0.0-preview.6.24214.1 | 687 | 4/23/2024 | |
| 8.0.0-preview.5.24201.12 | 908 | 4/9/2024 |