Share via


AspireSqlServerSqlClientExtensions.AddSqlServerClient Method

Definition

Registers 'Scoped' SqlConnection factory for connecting Azure SQL, MS SQL database using Microsoft.Data.SqlClient. Configures health check, logging and telemetry for the SqlClient.

public static void AddSqlServerClient (this Microsoft.Extensions.Hosting.IHostApplicationBuilder builder, string connectionName, Action<Aspire.Microsoft.Data.SqlClient.MicrosoftDataSqlClientSettings>? configureSettings = default);
static member AddSqlServerClient : Microsoft.Extensions.Hosting.IHostApplicationBuilder * string * Action<Aspire.Microsoft.Data.SqlClient.MicrosoftDataSqlClientSettings> -> unit
<Extension()>
Public Sub AddSqlServerClient (builder As IHostApplicationBuilder, connectionName As String, Optional configureSettings As Action(Of MicrosoftDataSqlClientSettings) = Nothing)

Parameters

builder
IHostApplicationBuilder

The IHostApplicationBuilder to read config from and add services to.

connectionName
String

A name used to retrieve the connection string from the ConnectionStrings configuration section.

configureSettings
Action<MicrosoftDataSqlClientSettings>

An optional delegate that can be used for customizing options. It's invoked after the settings are read from the configuration.

Exceptions

If required ConnectionString is not provided in configuration section.

Remarks

Reads the configuration from "Aspire:Microsoft:Data:SqlClient" section.

Applies to