# TraconSqlServerBuilderExtensions

> Tracon documentation. Tracon is a .NET package family that adds a control
> plane on Microsoft Agent Framework, published as NuGet packages that run
> inside your own ASP.NET Core application.
>
> Page: https://tracon.dev/api/tracon.traconsqlserverbuilderextensions/
> Summary: TraconSqlServerBuilderExtensions: Extensions that add SQL Server persistence to the Tracon chain.

<div class="api-provenance">Namespace Tracon · Assembly <code>Tracon.SqlServer.dll</code></div>

Extensions that add SQL Server persistence to the Tracon chain.

```csharp
public static class TraconSqlServerBuilderExtensions
```

<dl class="api-relations"><dt>Inheritance</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.object">object</a> ← <a href="/api/tracon.traconsqlserverbuilderextensions/">TraconSqlServerBuilderExtensions</a></dd><dt>Inherited Members</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.object.gettype">object.GetType()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone">object.MemberwiseClone()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.tostring">object.ToString()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)">object.Equals(object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)">object.Equals(object?, object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.referenceequals">object.ReferenceEquals(object?, object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.gethashcode">object.GetHashCode()</a></dd></dl>

## Methods

### <a id="Tracon_TraconSqlServerBuilderExtensions_UseSqlServer_Tracon_ITraconBuilder_System_String_"></a> UseSqlServer\(ITraconBuilder, string\)

Enables SQL Server persistence given a connection string.

```csharp
public static ITraconBuilder UseSqlServer(this ITraconBuilder builder, string connectionString)
```

#### Parameters

`builder` [ITraconBuilder](/api/tracon.itraconbuilder/)

The Tracon chain.

`connectionString` [string](https://learn.microsoft.com/dotnet/api/system.string)

The SQL Server connection string.

#### Returns

 [ITraconBuilder](/api/tracon.itraconbuilder/)

The continuation of the chain.

#### Remarks

```csharp
builder.AddTracon()
       .UseSqlServer(builder.Configuration.GetConnectionString("Tracon")!);
```

#### Exceptions

 [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)

`builder` is [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null).

 [ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception)

`connectionString` is empty.

### <a id="Tracon_TraconSqlServerBuilderExtensions_UseSqlServer_Tracon_ITraconBuilder_Microsoft_Extensions_Configuration_IConfiguration_"></a> UseSqlServer\(ITraconBuilder, IConfiguration\)

Enables SQL Server persistence, reading settings from the `Tracon:SqlServer` section.

```csharp
public static ITraconBuilder UseSqlServer(this ITraconBuilder builder, IConfiguration configurationSection)
```

#### Parameters

`builder` [ITraconBuilder](/api/tracon.itraconbuilder/)

The Tracon chain.

`configurationSection` [IConfiguration](https://learn.microsoft.com/dotnet/api/microsoft.extensions.configuration.iconfiguration)

The section settings are read from. Usually
`configuration.GetSection(TraconSqlServerOptions.SectionName)`.

#### Returns

 [ITraconBuilder](/api/tracon.itraconbuilder/)

The continuation of the chain.

#### Exceptions

 [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)

One of the parameters is [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null).

### <a id="Tracon_TraconSqlServerBuilderExtensions_UseSqlServer_Tracon_ITraconBuilder_System_Action_Tracon_TraconSqlServerOptions__"></a> UseSqlServer\(ITraconBuilder, Action<TraconSqlServerOptions\>\)

Enables SQL Server persistence with settings given in code.

```csharp
public static ITraconBuilder UseSqlServer(this ITraconBuilder builder, Action<TraconSqlServerOptions> configure)
```

#### Parameters

`builder` [ITraconBuilder](/api/tracon.itraconbuilder/)

The Tracon chain.

`configure` [Action](https://learn.microsoft.com/dotnet/api/system.action\-1)<[TraconSqlServerOptions](/api/tracon.traconsqlserveroptions/)\>

The settings mutator.

#### Returns

 [ITraconBuilder](/api/tracon.itraconbuilder/)

The continuation of the chain.

#### Remarks

Stores are registered with `ServiceCollectionDescriptorExtensions.Replace`,
not `TryAdd`. `AddTracon` has already registered the
in-memory stores with `TryAddSingleton` and runs *before* this
call in the chain; using `TryAdd` here would silently do nothing.

Overwriting is correct here because `UseSqlServer` is the
consumer's **explicit** choice. The "register with TryAdd"
rule is for Tracon's defaults, not for explicit calls.

#### Exceptions

 [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)

One of the parameters is [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null).
