Installation
Install the SQL Server hosting integration package in your AppHost project:Usage
Add SQL Server and Database
In your AppHost project (AppHost.cs), add a SQL Server resource and database:
Consume in Service
In your service project, reference the database using the client integration:Program.cs:
API Reference
AddSqlServer
Adds a SQL Server resource to the application model. A container is used for local development.Parameters
name- The name of the resource. This name will be used as the connection string name when referenced in a dependency.password- The parameter used to provide the administrator password for the SQL Server resource. Ifnulla random password will be generated.port- The host port for the SQL Server.
Returns
A reference to theIResourceBuilder<SqlServerServerResource>.
Remarks
The password must be at least 8 characters long and contain characters from three of the following four sets: Uppercase letters, Lowercase letters, Base 10 digits, and Symbols.AddDatabase
Adds a SQL Server database to the application model.Parameters
name- The name of the resource. This name will be used as the connection string name when referenced in a dependency.databaseName- The name of the database. If not provided, defaults to the same value asname.
Configuration Examples
Custom Port
Custom Password
Data Persistence with Volumes
Multiple Databases
Named Volumes
Bind Mounts
Connection Properties
When you reference a SQL Server resource usingWithReference, the following connection properties are made available to the consuming project.
SQL Server
| Property Name | Description |
|---|---|
Host | The hostname or IP address of the SQL Server |
Port | The port number the SQL Server is listening on |
Username | The username for authentication |
Password | The password for authentication |
Uri | The connection URI in mssql:// format, with the format mssql://{Username}:{Password}@{Host}:{Port} |
JdbcConnectionString | JDBC-format connection string, with the format jdbc:sqlserver://{Host}:{Port};trustServerCertificate=true. User and password credentials are provided as separate Username and Password properties. |
SQL Server Database
The SQL Server database resource inherits all properties from its parentSqlServerServerResource and adds:
| Property Name | Description |
|---|---|
Uri | The connection URI in mssql:// format, with the format mssql://{Username}:{Password}@{Host}:{Port}/{DatabaseName} |
JdbcConnectionString | JDBC connection string with database name, with the format jdbc:sqlserver://{Host}:{Port};trustServerCertificate=true;databaseName={DatabaseName}. User and password credentials are provided as separate Username and Password properties. |
DatabaseName | The name of the database |
Environment Variables
Aspire exposes each property as an environment variable named[RESOURCE]_[PROPERTY]. For instance:
- The
Uriproperty of a resource calledmydbbecomesMYDB_URI - The
DatabaseNameproperty becomesMYDB_DATABASENAME
Health Checks
The SQL Server hosting integration includes built-in health checks. When a resource is referenced as a dependency usingWaitFor, the dependent resource will wait until the SQL Server resource is able to service requests.
Container Image
The SQL Server hosting integration uses the official Microsoft SQL Server container image from the Microsoft Container Registry.By using the SQL Server container image, you accept the SQL Server End-User License Agreement (EULA). The container automatically sets
ACCEPT_EULA=Y.