.net 如何修复连接到 SQL Server 的错误:SSL 提供程序,错误:0 - 收到的消息意外或格式错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21681762/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 12:38:30  来源:igfitidea点击:

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

.netsql-server.net-4.5

提问by Kjensen

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

使用 Visual Studio 2012(或 2013)从我的本地开发箱连接 SQL Server 2008R2 SP1 时,我收到以下消息:

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.)

已成功与服务器建立连接,但随后在登录过程中出现错误。(提供程序:SSL 提供程序,错误:0 - 收到的消息意外或格式错误。)

My version of .Net framework locally is 4.5.50938

我本地的 .Net 框架版本是 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.

我的同事有完全相同的问题。我也相信我在重新安装电脑之前遇到了问题,当时我安装了 SSMS 2012,因为这也依赖于 .Net framework 4,而不是 .Net v2 作为 SSMS2008R2,它工作正常。Visual Studio 中的内部数据工具依赖于 .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.

问题并不总是存在,我相信它是在我第一次安装 Visual Studio 2013 时引入的 - 然后在重新安装后再次出现,很可能是在更新 .Net 框架之后。

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.

在我看来,当连接到 SQL Server 2008R2 SP1 时,问题似乎与此版本的 .Net 框架中的 System.Data 相关。

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

我怎样才能解决这个问题?是否有任何已知的修复、更新等?

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

不幸的是,目前无法选择更新 SQL Server 2008R2SP1。

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://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

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

enter image description here

在此处输入图片说明

回答by Frank Liao

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

按照 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
  • 卸载有问题的 LSP 或 BSP(即 Sophos Antivirus)
  • 卸载 .NET Framework 4.5.1(因此,VS 2013 将无法运行)
  • 安装.NET 框架 4.5.2

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

参考:http: //support.microsoft.com/kb/2915689

回答by Lionet Chen

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

经过长时间的艰苦搜索,我找到了一个解决方案,无需重新安装.NET Framework 4.5.1。您可以执行以下操作:

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

然后重新启动计算机。像魔术一样修复它,您可以保留 .NET 框架 4.5.1

回答by Kjensen

  1. Uninstall .Net framework 4.5.1
  2. Uninstall and then re-install Visual Studio 2012/2013 (repair does not work)
  1. 卸载 .Net 框架 4.5.1
  2. 卸载再重新安装Visual Studio 2012/2013(修复不起作用)

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.

.Net 4.5.1 似乎没有解决这个问题。卸载它破坏了我自己的 VS 2012 和我同事的 VS2013 - 但是在 VS 之后,一切似乎都正常了。我敢打赌,如果我再次安装 SQL Server Management Studio 2012,它也会再次对 SQL Server 2008SP1 安装起作用,我们有。

Others have reported the same fix in this thread

其他人在此线程中报告了相同的修复

回答by Allen Xia

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

作为一种解决方法,我刚刚卸载了 .NET framework 4.5.1 并安装了 .NET framework 4.5。然后一切正常!

For your info, the bug has been reported here

供您参考,该错误已在此处报告

回答by hholtij

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

我安装了 VS 2013,当然不想回到以前的版本。

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.

根据 Frank Liao 的回答,我所要做的就是安装 .NET 4.5.2。我不必卸载任何东西。

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

只需从 Frank Liao 的帖子中获取 Web 安装程序并运行它。

Thanks Frank!

谢谢弗兰克!

回答by Sandip Patel

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

netsh winsock reset从命令行参数尝试过。它现在已经工作了。

回答by eka808

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

对我来说,解决方案是从连接字符串中删除它

Encrypt=True;TrustServerCertificate=False;

Without it, it works but obviously without encryption.

没有它,它可以工作,但显然没有加密。