Skip to content
DocsTry Aspire
DocsTry

AspireSqlServerSqlClientExtensions Methods

ClassMethods2 members
Extension methods for configuring SqlClient connection to Azure SQL, MS SQL server
AddKeyedSqlServerClient(IHostApplicationBuilder, string, Action<MicrosoftDataSqlClientSettings>)Section titled AddKeyedSqlServerClient(IHostApplicationBuilder, string, Action<MicrosoftDataSqlClientSettings>)extension
Registers 'Scoped' SqlClient.SqlConnection factory for given name for connecting Azure SQL, MsSQL database using Microsoft.Data.SqlClient. Configures health check, logging and telemetry for the SqlClient.
public static class AspireSqlServerSqlClientExtensions
{
public static void AddKeyedSqlServerClient(
this IHostApplicationBuilder builder,
string name,
Action<MicrosoftDataSqlClientSettings>? configureSettings = null)
{
// ...
}
}
builderIHostApplicationBuilderThe Hosting.IHostApplicationBuilder to read config from and add services to.
namestringThe name of the component, which is used as the ServiceDescriptor.ServiceKey of the service and also to retrieve the connection string from the ConnectionStrings configuration section.
configureSettingsAction<MicrosoftDataSqlClientSettings>optionalAn optional method that can be used for customizing options. It's invoked after the settings are read from the configuration.
InvalidOperationExceptionIf required MicrosoftDataSqlClientSettings.ConnectionString is not provided in configuration section.
Reads the configuration from "Aspire:Microsoft:Data:SqlClient:{name}" section.
AddSqlServerClient(IHostApplicationBuilder, string, Action<MicrosoftDataSqlClientSettings>)Section titled AddSqlServerClient(IHostApplicationBuilder, string, Action<MicrosoftDataSqlClientSettings>)extension
Registers 'Scoped' SqlClient.SqlConnection factory for connecting Azure SQL, MS SQL database using Microsoft.Data.SqlClient. Configures health check, logging and telemetry for the SqlClient.
public static class AspireSqlServerSqlClientExtensions
{
public static void AddSqlServerClient(
this IHostApplicationBuilder builder,
string connectionName,
Action<MicrosoftDataSqlClientSettings>? configureSettings = null)
{
// ...
}
}
builderIHostApplicationBuilderThe Hosting.IHostApplicationBuilder to read config from and add services to.
connectionNamestringA name used to retrieve the connection string from the ConnectionStrings configuration section.
configureSettingsAction<MicrosoftDataSqlClientSettings>optionalAn optional delegate that can be used for customizing options. It's invoked after the settings are read from the configuration.
InvalidOperationExceptionIf required MicrosoftDataSqlClientSettings.ConnectionString is not provided in configuration section.
Reads the configuration from "Aspire:Microsoft:Data:SqlClient" section.