Aspire.Hosting.SqlServer 17.0.0
SQL Server hosting integration
Use this integration to model, configure, and orchestrate a SQL Server database resource in an Aspire solution.
Getting started
Add the integration
From your AppHost directory, add the Aspire.Hosting.SqlServer integration with the Aspire CLI:
aspire add Aspire.Hosting.SqlServer
aspire add Aspire.Hosting.Dotnet
Usage example
In the AppHost, add a SQL Server resource and reference it from another resource with either C# or TypeScript:
C#
var db = builder.AddSqlServer("sql").AddDatabase("db");
var myService = builder.AddDotnetProject("myservice", "../MyService/MyService.csproj")
.WithReference(db);
TypeScript
const db = await builder.addSqlServer("sql").addDatabase("db");
const myService = await builder.addNodeApp("myService", "../my-service", "server.js")
.withReference(db);
SQL REPL
Call WithRepl() to opt into a REPL command on the SQL Server resource in the dashboard:
builder.AddSqlServer("sqlserver").WithRepl();
await builder.addSqlServer("sqlserver").withRepl();
REPL access is disabled by default and is available only in run mode. Enable it only for trusted dashboard
users: the shell runs as sa and can execute server-side operating system commands when enabled.
Sharing the dashboard through a tunnel, Codespaces, or VS Code remote development also exposes this
capability to users who can execute resource commands.
Use QUIT before closing the terminal tab to end the session cleanly. Closing the tab alone can
leave sqlcmd running inside the container. Stopping the container also ends any remaining REPL processes.
While the container is running, the command opens sqlcmd in the terminal dock. It connects inside the container as sa to the master database, using the configured password without putting it in command-line arguments. No local SQL client installation is required.
Enter SQL statements followed by GO on its own line to execute a batch:
SELECT DB_NAME();
GO
Use USE [db]; followed by GO to switch databases, and QUIT to exit. The command trusts the local server's self-signed certificate, matching the integration's local connection string.
Select the client executable
The REPL invokes /opt/mssql-tools18/bin/sqlcmd directly by default, matching the tools version included
in the integration's default 2022-latest image. It does not probe for another client or invoke a shell.
No override is needed when using the default image.
When pinning an older image that includes /opt/mssql-tools/bin/sqlcmd, select the version 17 command.
Replace <your-pinned-image-tag> with the tag of that image:
C#
builder.AddSqlServer("sqlserver")
.WithImageTag("<your-pinned-image-tag>")
.WithRepl(options => options.Command = SqlServerReplCommand.Version17);
TypeScript
import { SqlServerReplCommand } from "./.aspire/modules/aspire.mjs";
await builder.addSqlServer("sqlserver")
.withImageTag("<your-pinned-image-tag>")
.withRepl({
configure: async options => {
await options.command.set(SqlServerReplCommand.Version17);
}
});
SqlServerReplCommand.Version17 and SqlServerReplCommand.Version18 are string constants for the
well-known executable paths. Choose based on the client tools installed in the image, not the SQL Server
version. Changing Command does not install tools or change the image.
This command is available only in run mode and uses the configured Docker or Podman runtime.
For an image that installs sqlcmd elsewhere, configure the resource with that executable path instead:
sqlServer.WithRepl(options => options.Command = "/usr/local/bin/sqlcmd");
await sqlServer.withRepl({
configure: async options => {
await options.command.set("/usr/local/bin/sqlcmd");
}
});
Run a wrapper script
Set Command to an executable script inside the container to run work before and after the interactive
SQL session. For example, place these two files in a sql directory under the AppHost directory.
sql/Dockerfile
FROM mcr.microsoft.com/mssql/server:2022-latest
COPY --chmod=755 sqlcmd-wrapper.sh /usr/local/bin/sqlcmd-wrapper
sql\sqlcmd-wrapper.sh
#!/bin/sh
echo "Running pre-session work"
/opt/mssql-tools18/bin/sqlcmd "$@"
status=$?
echo "Running post-session work"
exit "$status"
Replace the echoed messages with the work you want to run, then configure Aspire to build the image and launch the wrapper:
C#
builder.AddSqlServer("sqlserver")
.WithDockerfile("sql")
.WithRepl(options => options.Command = "/usr/local/bin/sqlcmd-wrapper");
TypeScript
await builder.addSqlServer("sqlserver")
.withDockerfile("sql")
.withRepl({
configure: async options => {
await options.command.set("/usr/local/bin/sqlcmd-wrapper");
}
});
The wrapper receives Aspire's usual sqlcmd arguments and the SQLCMDPASSWORD environment variable.
Forward "$@" to preserve argument boundaries; do not put the password in arguments or log it.
The example preserves sqlcmd's exit code.
Save the script with LF line endings and make it executable; the Dockerfile's COPY --chmod=755
sets the permissions. Its #!/bin/sh line selects the interpreter when the script is executed.
Do not use exec to invoke sqlcmd if you need work to run afterward, because it replaces the wrapper
process. Post-session work runs when sqlcmd returns; forcibly stopping the container can prevent it.
Connection Properties
When you reference a SQL Server resource using WithReference, the following connection properties are made available to the consuming project:
SQL Server server
The SQL Server server resource exposes the following connection properties:
| 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 parent SqlServerServerResource 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 |
Aspire exposes each property as an environment variable named [RESOURCE]_[PROPERTY]. For instance, the Uri property of a resource called db1 becomes DB1_URI.
Additional documentation
https://aspire.dev/integrations/gallery/ https://aspire.dev/integrations/databases/sql-server/sql-server-host/
Feedback & contributing
No packages depend on Aspire.Hosting.SqlServer.
.NET 10.0
- Aspire.Hosting (>= 17.0.0)
- AspNetCore.HealthChecks.SqlServer (>= 9.0.0)
- AspNetCore.HealthChecks.Uris (>= 9.0.0)
- Google.Protobuf (>= 3.36.1)
- Grpc.AspNetCore (>= 2.83.0)
- Grpc.Net.ClientFactory (>= 2.83.0)
- Grpc.Tools (>= 2.83.0)
- Hex1b (>= 0.173.0)
- KubernetesClient (>= 19.0.2)
- MessagePack (>= 2.5.307)
- Microsoft.Bcl.Cryptography (>= 10.0.15)
- Microsoft.Data.SqlClient (>= 7.1.1)
- Microsoft.Extensions.Caching.Memory (>= 10.0.15)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.15)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.15)
- Microsoft.Extensions.Configuration.EnvironmentVariables (>= 10.0.15)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.15)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 10.0.15)
- Microsoft.Extensions.FileSystemGlobbing (>= 10.0.15)
- Microsoft.Extensions.Hosting (>= 10.0.15)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.15)
- Microsoft.Extensions.Http (>= 10.0.15)
- Microsoft.Extensions.Logging (>= 10.0.15)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.15)
- Microsoft.Extensions.Options (>= 10.0.15)
- Microsoft.Extensions.Primitives (>= 10.0.15)
- ModelContextProtocol (>= 1.4.1)
- Newtonsoft.Json (>= 13.0.4)
- OpenTelemetry.Exporter.OpenTelemetryProtocol (>= 1.18.0)
- OpenTelemetry.Extensions.Hosting (>= 1.18.0)
- Polly.Core (>= 8.7.0)
- Semver (>= 3.0.0)
- StreamJsonRpc (>= 2.25.29)
- System.IO.Hashing (>= 10.0.15)
- System.Security.Cryptography.Pkcs (>= 10.0.15)
- YamlDotNet (>= 18.1.0)
| Version | Downloads | Last updated |
|---|---|---|
| 17.0.0 | 7 | 11/18/2026 |
| 13.6.5 | 12 | 11/10/2026 |
| 13.6.4 | 16 | 10/24/2026 |
| 13.6.3 | 13 | 10/22/2026 |
| 13.6.2 | 15 | 10/21/2026 |
| 13.6.1 | 16 | 10/08/2026 |
| 13.6.0 | 23 | 09/30/2026 |
| 13.5.4 | 22 | 09/16/2026 |
| 13.5.3 | 25 | 08/27/2026 |
| 13.5.2 | 22 | 08/22/2026 |
| 13.5.1 | 25 | 08/20/2026 |
| 13.5.0 | 24 | 08/19/2026 |
| 13.4.6 | 33 | 06/22/2026 |
| 13.4.5 | 31 | 06/18/2026 |
| 13.4.4 | 35 | 06/15/2026 |
| 13.4.3 | 25 | 06/11/2026 |
| 13.4.2 | 39 | 06/04/2026 |
| 13.4.1 | 29 | 06/04/2026 |
| 13.4.0 | 33 | 06/05/2026 |
| 13.3.5 | 39 | 05/23/2026 |
| 13.3.4 | 35 | 05/20/2026 |
| 13.3.3 | 40 | 05/20/2026 |
| 13.3.2 | 48 | 05/16/2026 |
| 13.3.1 | 36 | 05/14/2026 |
| 13.3.0 | 37 | 05/10/2026 |
| 13.2.4 | 49 | 04/27/2026 |
| 13.2.3 | 43 | 04/22/2026 |
| 13.2.2 | 46 | 04/12/2026 |
| 13.2.1 | 42 | 04/01/2026 |
| 13.2.0 | 45 | 03/24/2026 |
| 13.1.3 | 45 | 03/22/2026 |
| 13.1.2 | 57 | 02/27/2026 |
| 13.1.1 | 54 | 02/15/2026 |
| 13.1.0 | 57 | 12/18/2025 |
| 13.0.2 | 56 | 12/11/2025 |
| 13.0.1 | 16 | 09/28/2026 |
| 13.0.0 | 61 | 12/14/2025 |
| 9.5.2 | 59 | 12/18/2025 |
| 9.5.1 | 12 | 10/02/2026 |
| 9.5.0 | 45 | 12/12/2025 |
| 9.4.2 | 52 | 12/12/2025 |
| 9.4.1 | 6 | 10/01/2026 |
| 9.4.0 | 12 | 10/07/2026 |
| 9.3.2 | 40 | 12/14/2025 |
| 9.3.1 | 39 | 12/11/2025 |
| 9.3.0 | 38 | 01/01/2026 |
| 9.2.1 | 40 | 12/23/2025 |
| 9.2.0 | 52 | 12/12/2025 |
| 9.1.0 | 44 | 12/11/2025 |
| 9.0.0 | 44 | 12/11/2025 |
| 9.0.0-rc.1.24511.1 | 47 | 12/11/2025 |
| 8.2.2 | 46 | 12/29/2025 |
| 8.2.1 | 48 | 12/11/2025 |
| 8.2.0 | 44 | 01/01/2026 |
| 8.1.0 | 14 | 10/08/2026 |
| 8.0.2 | 48 | 12/28/2025 |
| 8.0.1 | 43 | 12/12/2025 |
| 8.0.0 | 41 | 12/14/2025 |
| 8.0.0-preview.7.24251.11 | 49 | 12/12/2025 |
| 8.0.0-preview.6.24214.1 | 46 | 12/13/2025 |
| 8.0.0-preview.5.24201.12 | 40 | 12/19/2025 |