Lewati ke konten
Docs Try Aspire
Docs Try
SQL Server logo

This page describes how consuming apps connect to a SQL Server resource that’s already modeled in your AppHost. For the AppHost API surface — adding a SQL Server instance, databases, data volumes, bind mounts, and more — see SQL Server Hosting integration.

When you reference a SQL Server resource from your AppHost, Aspire injects the connection information into the consuming app as environment variables. Your app can either read those environment variables directly — the pattern works the same from any language — or, in C#, use the Aspire SQL Server client integration for automatic dependency injection, health checks, and telemetry.

Aspire exposes each property as an environment variable named [RESOURCE]_[PROPERTY]. For instance, the Uri property of a resource called sqldb becomes SQLDB_URI.

The SQL Server server resource exposes the following connection properties:

Property NameDescription
HostThe hostname or IP address of the SQL Server instance
PortThe port number the SQL Server instance is listening on
UsernameThe username for authentication
PasswordThe password for authentication
UriThe connection URI in mssql:// format, with the format mssql://{Username}:{Password}@{Host}:{Port}
JdbcConnectionStringJDBC-format connection string, with the format jdbc:sqlserver://{Host}:{Port};trustServerCertificate=true. User and password credentials are provided as separate Username and Password properties.

Example connection strings:

Uri: mssql://sa:p%40ssw0rd1@localhost:1433
JdbcConnectionString: jdbc:sqlserver://localhost:1433;trustServerCertificate=true

The SQL Server database resource inherits all properties from its parent server resource and adds:

Property NameDescription
UriThe connection URI with the database name, with the format mssql://{Username}:{Password}@{Host}:{Port}/{DatabaseName}
JdbcConnectionStringJDBC connection string with the 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.
DatabaseNameThe name of the database

Example connection strings:

Uri: mssql://sa:p%40ssw0rd1@localhost:1433/catalog
JdbcConnectionString: jdbc:sqlserver://localhost:1433;trustServerCertificate=true;databaseName=catalog

Pick the language your consuming app is written in. Each example assumes your AppHost adds a SQL Server database resource named sqldb and references it from the consuming app.