An error occured during the pre-login handshake

Tim picture Tim · Jan 8, 2013 · Viewed 7.4k times · Source

I had a C# application that communicates with a database using Linq to SQL and was working just fine when I last tested it a month ago. However, it is now throwing the following exception:

A first chance exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
------ Exception ------
Error:  A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: SSL Provider, error: 0 - The received certificate has expired.)

I am digitally signing the code with a Verisign key, but it has not expired. I don't digitally sign until I build the installer, and this is occurring on my dev system in debug, so the code had not been signed.

It is also happening on other systems where the software was signed and installed. These systems access the same test database as I use on my dev system, and were working previously.

The line of code that causes the error follows:

        List<req> results = new List<req>();

        using (var db = new MyDbDataContext(connectionString))
        {
            var query =
                from item in db.reqs
                where item.senddate == null
                select item;

            results = query.ToList();
        }

The error happens when I call results = query.ToList();.

I use the following connection string:

Data Source=<removed>;Initial Catalog=<removed>;UID=sa;PWD=<removed>;Encrypt=true;Integrated Security=false

I am able to connect if I set Encrypt=false, but that is not a viable solution.

Again, this worked just fine the last time I tested it a couple weeks ago. Any insights as to what might be happening would be greatly appreciated.

Answer

Tim picture Tim · Jan 9, 2013

I managed to find a solution from this post.

Basically, I added TrustServerCertificate=True to my connection text, and everything started working again. I'm not sure why it stopped working in the first place, and if anyone knows if this will be a permanent solution or not, I would love to find out more about what happened.

Thank you to Carson63000 and Jacco for the suggestions.