SQL Server connection string rejects Trust Server Certificate with spaces
Your error
ArgumentException: Keyword not supported: 'trust server certificate'.1 more line it can showFix it fast
Most common cause, 1 of 2The app still runs on System.Data.SqlClient
Write the keyword without spaces, which both drivers accept.
"ConnectionStrings": {
"Default": "Server=db01;Database=Shop;User Id=app;Password=...;Encrypt=True;TrustServerCertificate=True"
}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.
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.
dotnet list package --include-transitive | grep -i sqlclientThen find the line you see in this list and open its fix:
- 1The app still runs on System.Data.SqlClient
The package list shows System.Data.SqlClient, or the code imports the System.Data.SqlClient namespace - 2Microsoft.Data.SqlClient is older than 2.0, often through EF Core 3.1
The 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.
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.
"ConnectionStrings": {
"Default": "Server=db01;Database=Shop;User Id=app;Password=...;Encrypt=True;TrustServerCertificate=True"
}Verify
The app opens its first connection without the ArgumentException.
dotnet runConfirmed by learn.microsoft.com
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.
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.
dotnet add package Microsoft.Data.SqlClient --version 7.1.2Verify
The package list now shows 7.1.2 as a top-level reference, and the string with spaces loads.
dotnet list package | grep -i sqlclientConfirmed by raw.githubusercontent.com
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.