How to connect a certificate when using s SqlConnection ? From SqlConnection Connection String Parameter Keywords and values , I know that I can set Encrypted to true to force (encourage?) The use of SSL / TLS.
However, to bind the certificate, I believe that we need to use the ServerCertificateValidationCallback from the ServicePointManager (the sample code suggested by Arne Vajhøj for HTTP / HTTPS). I do not understand how to connect in PinCertificate (from ServicePointManager ) to SqlConnection .
UPDATE: When chatting with Arne Wajhai at microsoft.public.dotnet.languages.csharp, it seems that he may not have the desired control over the connection. Vajhøj offered a link to Encrypt connections to SQL Server .
public static void Main(string[] args) { ServicePointManager.ServerCertificateValidationCallback = PinCertificate; WebRequest wr = WebRequest.Create("https://www.google.com/"); wr.GetResponse(); } public static bool PinCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { byte[] chash = certificate.GetCertHash(); StringBuilder sb = new StringBuilder(chash.Length * 2); foreach (byte b in chash) sb.AppendFormat("{0:X2}", b);
source share