Kjensen
Kjensen

Reputation: 12374

How do I fix an error connecting to SQL Server: SSL Provider, error: 0 - The message received was unexpected or badly formatted

When connecting from my local dev box using Visual Studio 2012 (or 2013) against a SQL Server 2008R2 SP1, I get this message:

A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - The message received was unexpected or badly formatted.)

My version of .Net framework locally is 4.5.50938

My colleague has the exact same problem. I also believe I had the problem earlier, before re-installing the pc, when I had SSMS 2012 installed, as that also relies on .Net framework 4, not .Net v2 as SSMS2008R2, which works fine. It would also make sense, that the internal data tooling in visual studio relies on .Net 4.

The problem has not always been there, and I believe it was introduced when I first installed Visual Studio 2013 - and then again later after a reinstall, most likely after updating the .Net framework.

The problem seems to me to be related to System.Data in this version of the .Net framework, when connecting against a SQL Server 2008R2 SP1.

How can I fix this? Are there any known fixes, updates etc?

Unfortunately updating SQL Server 2008R2SP1 is not currently an option.

I have also searched for solutions, but have found nothing usable, so far. Here are a couple of links to other posts with similar issue:

http://social.msdn.microsoft.com/Forums/en-US/ea2c470f-14ba-4864-8a39-1396f4e361e8/sqlconnection-now-failing-exception-when-connecting-to-remote-instance?forum=sqldataaccess

http://www.sqlservercentral.com/Forums/Topic1529609-2799-1.aspx

enter image description here

Upvotes: 15

Views: 92806

Answers (12)

Steve Jones
Steve Jones

Reputation: 1

I was getting the certificate error using SSMS v20 but when I used SSMS v19, it worked as expected.

Upvotes: 0

Ameen Rabea
Ameen Rabea

Reputation: 224

The only thing that I did and solved the issue for me; was selecting (ticking) the option "Trust server certificate" as you can see here:

enter image description here

Of course I entered the password in its field too.

Upvotes: 0

Chami Mohammed
Chami Mohammed

Reputation: 624

For me it worked by two ways:

1- changing the Encrypt From Mandatory to Optional as shows in the image below;

or

2- leaving it Mandatory but check the Trust Server Certificate checkbox

enter image description here

Upvotes: 0

Abdelwahid Oubaalla
Abdelwahid Oubaalla

Reputation: 865

Try adding

TrustServerCertificate=True;

to your connection string. thad has worked form me . I use Asp.netCore 6

Upvotes: 9

Shamyrat Pashshyyev
Shamyrat Pashshyyev

Reputation: 174

I was using mssql management studio 2019. I just clicked Options>>Connection Properties>Encrypt connection (uncheck) and it worked

Upvotes: 1

eka808
eka808

Reputation: 2317

For me, the solution was to remove this from the connection string

Encrypt=True;TrustServerCertificate=False;

Without it, it works but obviously without encryption.

Upvotes: 7

Lionet Chen
Lionet Chen

Reputation: 842

After long and hard searching I found a solution, without reinstalling .NET framework 4.5.1. You can do the following:

Execute the command below under command line mode, with administrative privilege (haven't tried without admin privilege, might as well work)

netsh winsock reset

Then restart your computer. That fixed it like magic and you can keep .NET framework 4.5.1

Upvotes: 8

Kjensen
Kjensen

Reputation: 12374

  1. Uninstall .Net framework 4.5.1
  2. Uninstall and then re-install Visual Studio 2012/2013 (repair does not work)

It seems there is no fix for this with .Net 4.5.1. Uninstalling it broke VS 2012 for myself and VS2013 for my colleague - but after VS, everything seems to work. I would be willing to bet, that if I installed SQL Server Management Studio 2012 again, that would also work again against the SQL Server 2008SP1 installation, we have.

Others have reported the same fix in this thread

Upvotes: 2

user900202
user900202

Reputation:

As a workaround, I just uninstalled .NET framework 4.5.1 and installed .NET framework 4.5. Then everything works!

For your info, the bug has been reported here

Upvotes: 1

Sandip Patel
Sandip Patel

Reputation: 1

I tried netsh winsock reset from command line argument. It is worked as of now.

Upvotes: 0

hholtij
hholtij

Reputation: 2936

I have VS 2013 installed and certainly didn't want to go back to a previous version.

Based on Frank Liao's answer, all I had to do to make it work was install .NET 4.5.2. I didn't have to uninstall anything.

Just get the web installer from Frank Liao's post and run it.

Thanks Frank!

Upvotes: 0

Frank Liao
Frank Liao

Reputation: 641

You are only left with the following options as instructed by Microsoft:

  • Uninstall offending LSP or BSP (i.e., Sophos Antivirus)
  • Uninstall .NET Framework 4.5.1 (therefore, VS 2013 will not work)
  • Install .NET Framework 4.5.2

Reference: http://support.microsoft.com/kb/2915689

Upvotes: 11

Related Questions