I want to establish TLS1.3 Protocol communication between System.Data.SqlClient
and SQL Server 2022.
As per Microsoft TDS8, we need to add Encrypt=strict key in the connection string to established TLS 1.3 connection. But when I added this key below error thrown
Invalid value for key 'encrypt'
When I keep encrypt=true
then a TLS 1.2 connection is established. (proper certificate I am using).
Looks like encrypt takes only true/false values only. No strict/optional/mandatory even though MS suggested it.
Sample code:
using System.Data.SqlClient;
namespace SQLClient
{
internal class Program
{
//sql conn string
static string sConnStringRemoteSql2k22 = "Encrypt=Strict;Password=Password@123;Persist Security Info=True;User ID=sa;Initial Catalog=Testdb;Data Source=sql2k22.test.com;Application Name=test";
static void Main(string[] args)
{
SqlConnection conn = new SqlConnection(sConnStringRemoteSql2k22);
try
{
string query = "Select * from Players";
conn.Open();
SqlCommand cmd = new SqlCommand(query, conn);
using (SqlDataReader dr = cmd.ExecuteReader())
{
while (dr.Read())
{
Console.WriteLine(dr["Name"].ToString() + " " + dr["dept"].ToString());
}
}
}
finally
{
conn.Close();
}
Console.ReadLine();
}
}
}
Environment:
Microsoft SQL Server 2022 (RTM-CU10) (KB5031778) - 16.0.4095.4 (X64) Express Edition (64-bit) on Windows Server 2022 Standard 10.0 (Build 20348: ) (Hypervisor)
.NET Framework 4.8.1
System.Data version 4.0.0.0
OS: Windows Server 2022
Why does encrypt=strict
not work with SqlClient
? Or is there any key I need to add to an established TLS 1.3 connection?