Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Databases and Redis

SQL Server connection string rejects Trust Server Certificate with spaces

Your error

ArgumentException: Keyword not supported: 'trust server certificate'.1 more line it can show

Fix it fast

Most common cause, 1 of 2

The app still runs on System.Data.SqlClient

Write the keyword without spaces, which both drivers accept.

Fix
"ConnectionStrings": {
  "Default": "Server=db01;Database=Shop;User Id=app;Password=...;Encrypt=True;TrustServerCertificate=True"
}
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

ArgumentException: Keyword not supported: 'trust server certificate' means the SQL Server driver parsing the string does not know the spaced synonym. Only Microsoft.Data.SqlClient 2.0 and later accept it; System.Data.SqlClient and Microsoft.Data.SqlClient 1.x, which EF Core 3.1 pulls in, know only TrustServerCertificate. Remove the spaces, or upgrade to Microsoft.Data.SqlClient 7.1.

  • Applies to Microsoft.Data.SqlClient 7.1.2, System.Data.SqlClient 4.9.1 (deprecated), .NET 10 and .NET 11 SDK
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

List every SqlClient package the project resolves, including transitive ones. The result tells you which driver parses the string and whether its version knows the spaced keywords. From the .NET 10 SDK on, the noun-first spelling, dotnet package list, does the same job.

Run this first
dotnet list package --include-transitive | grep -i sqlclient

Then find the line you see in this list and open its fix:

  1. 1The app still runs on System.Data.SqlClientThe package list shows System.Data.SqlClient, or the code imports the System.Data.SqlClient namespace
  2. 2Microsoft.Data.SqlClient is older than 2.0, often through EF Core 3.1The package list shows Microsoft.Data.SqlClient 1.x, typically as a transitive dependency of Microsoft.EntityFrameworkCore.SqlServer 3.1

What does the error look like?

  • ArgumentException: Keyword not supported: 'trust server certificate'.
  • System.ArgumentException: Keyword not supported: 'application intent'.

Cause 1 of 2

The app still runs on System.Data.SqlClient

You seeThe package list shows System.Data.SqlClient, or the code imports the System.Data.SqlClient namespace

Check

The legacy driver's ConnectionString reference names the keyword only as TrustServerCertificate, without a spaced variant, so it throws while parsing. Microsoft has deprecated the package and points to Microsoft.Data.SqlClient instead.

Check
grep -rn "using System.Data.SqlClient" --include=*.cs .

Fix

Write the keyword without spaces, which both drivers accept. For a lasting fix, swap the package and the namespace to Microsoft.Data.SqlClient.

Fix
"ConnectionStrings": {
  "Default": "Server=db01;Database=Shop;User Id=app;Password=...;Encrypt=True;TrustServerCertificate=True"
}

Verify

The app opens its first connection without the ArgumentException.

Verify
dotnet run

Confirmed by learn.microsoft.com

Did this fix it?

Cause 2 of 2

Microsoft.Data.SqlClient is older than 2.0, often through EF Core 3.1

You seeThe package list shows Microsoft.Data.SqlClient 1.x, typically as a transitive dependency of Microsoft.EntityFrameworkCore.SqlServer 3.1

Check

The spaced synonyms, such as Trust Server Certificate and Application Intent, arrived in Microsoft.Data.SqlClient 2.0. EF Core 3.1's SQL Server provider only requires version 1.1.3 or higher, so a project that never references the driver directly can stay on 1.x and reject them. Since 2.0 the connection string builder writes the spaced names, so a string produced by newer tooling can reach an older app.

Check
dotnet list package --include-transitive | grep -i "Microsoft.Data.SqlClient"

Fix

Reference a current Microsoft.Data.SqlClient directly so NuGet resolves it above the old floor, or remove the spaces from the keyword if the project must stay as it is.

Fix
dotnet add package Microsoft.Data.SqlClient --version 7.1.2

Verify

The package list now shows 7.1.2 as a top-level reference, and the string with spaces loads.

Verify
dotnet list package | grep -i sqlclient

Confirmed by raw.githubusercontent.com

Did this fix it?

How do I stop it coming back?

  • Write SQL Server keywords in their unspaced form in config files, since every driver version accepts those.
  • Reference Microsoft.Data.SqlClient explicitly in projects that use EF Core, instead of relying on the provider's minimum version.
  • Check connection strings that deployment tooling rewrites before they reach production config.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: Raheeb, Loade Driver, Dhero.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.