【问题标题】:Handshake exception occurring when connecting to SQL Server Azure with .NET 4.5使用 .NET 4.5 连接到 SQL Server Azure 时发生握手异常
【发布时间】:2018-05-01 03:13:12
【问题描述】:

所以我打开了一些大约 2 个月没有动过的代码。

上次我打开应用程序时,所有单元测试都通过了。现在没有代码更改,我的所有数据单元测试都失败并出现以下错误:

初始化方法 PerTrac.Pictor.Data.Test.RequestLogRepositoryShould.CreateLog 抛出 例外。 System.Data.EntityException:System.Data.EntityException: 基础提供程序在打开时失败。 ---> System.Data.SqlClient.SqlException:连接成功 与服务器建立,但随后发生错误 登录前握手。 (提供者:SSL 提供者,错误:0 - 等待 操作超时。)---> System.ComponentModel.Win32Exception: 等待操作超时。

我意识到存在与此类似的问题,但这些解决方案对我的情况没有任何影响。

有没有人在实体框架和 SQL Azure 上遇到过这个错误?

我应该注意,我可以使用相同的凭据从 SSMS 连接而没有问题。我没有在禁用协议上设置强制加密,并且我已经多次重置本地 IIS。

【问题讨论】:

    标签: .net sql-server entity-framework azure azure-sql-database


    【解决方案1】:

    很可能您的计算机上安装了一些应用程序,该应用程序使用已弃用的网络协议来拦截网络流量。正确的解决方案是希望禁用或卸载这些应用程序。

    运行命令行命令netsh WinSock Show Catalog >> winsock.txt然后notepad winsock.txt打开文件。

    查看返回的每个 Winsock 目录提供程序条目。如果 Service Flags 值设置了 0x20000 位,则提供程序使用 IFS 句柄并且可以正常工作。如果“服务标志”0x20000 位被清除(未设置),则它是非 IFS BSP 或 LSP,可能是一个问题。尝试禁用此应用程序并让我们知道它是否有效。

    查看文本文件结果时,请忽略“名称空间提供者条目”。他们不是问题。

    下面是 netsh WinSock Show Catalog 文件输出的干净系统的样例。

    Winsock Catalog Provider Entry
    ------------------------------------------------------
    Entry Type:                         Base Service Provider
    Description:                        MSAFD Tcpip [TCP/IP]
    Provider ID:                        {E70F1AA0-AB8B-11CF-8CA3-00805F48A192}
    Provider Path:                      %SystemRoot%\system32\mswsock.dll
    Catalog Entry ID:                   1001
    Version:                            2
    Address Family:                     2
    Max Address Length:                 16
    Min Address Length:                 16
    Socket Type:                        1
    Protocol:                           6
    Service Flags:                      0x20066
    Protocol Chain Length:              1
    
    Winsock Catalog Provider Entry
    ------------------------------------------------------
    Entry Type:                         Base Service Provider
    Description:                        MSAFD Tcpip [UDP/IP]
    Provider ID:                        {E70F1AA0-AB8B-11CF-8CA3-00805F48A192}
    Provider Path:                      %SystemRoot%\system32\mswsock.dll
    Catalog Entry ID:                   1002
    Version:                            2
    Address Family:                     2
    Max Address Length:                 16
    Min Address Length:                 16
    Socket Type:                        2
    Protocol:                           17
    Service Flags:                      0x20609
    Protocol Chain Length:              1
    
    Winsock Catalog Provider Entry
    ------------------------------------------------------
    Entry Type:                         Base Service Provider
    Description:                        MSAFD Tcpip [RAW/IP]
    Provider ID:                        {E70F1AA0-AB8B-11CF-8CA3-00805F48A192}
    Provider Path:                      %SystemRoot%\system32\mswsock.dll
    Catalog Entry ID:                   1003
    Version:                            2
    Address Family:                     2
    Max Address Length:                 16
    Min Address Length:                 16
    Socket Type:                        3
    Protocol:                           0
    Service Flags:                      0x20609
    Protocol Chain Length:              1
    
    Winsock Catalog Provider Entry
    ------------------------------------------------------
    Entry Type:                         Base Service Provider
    Description:                        MSAFD Tcpip [TCP/IPv6]
    Provider ID:                        {F9EAB0C0-26D4-11D0-BBBF-00AA006C34E4}
    Provider Path:                      %SystemRoot%\system32\mswsock.dll
    Catalog Entry ID:                   1004
    Version:                            2
    Address Family:                     23
    Max Address Length:                 28
    Min Address Length:                 28
    Socket Type:                        1
    Protocol:                           6
    Service Flags:                      0x20066
    Protocol Chain Length:              1
    
    Winsock Catalog Provider Entry
    ------------------------------------------------------
    Entry Type:                         Base Service Provider
    Description:                        MSAFD Tcpip [UDP/IPv6]
    Provider ID:                        {F9EAB0C0-26D4-11D0-BBBF-00AA006C34E4}
    Provider Path:                      %SystemRoot%\system32\mswsock.dll
    Catalog Entry ID:                   1005
    Version:                            2
    Address Family:                     23
    Max Address Length:                 28
    Min Address Length:                 28
    Socket Type:                        2
    Protocol:                           17
    Service Flags:                      0x20609
    Protocol Chain Length:              1
    
    Winsock Catalog Provider Entry
    ------------------------------------------------------
    Entry Type:                         Base Service Provider
    Description:                        MSAFD Tcpip [RAW/IPv6]
    Provider ID:                        {F9EAB0C0-26D4-11D0-BBBF-00AA006C34E4}
    Provider Path:                      %SystemRoot%\system32\mswsock.dll
    Catalog Entry ID:                   1006
    Version:                            2
    Address Family:                     23
    Max Address Length:                 28
    Min Address Length:                 28
    Socket Type:                        3
    Protocol:                           0
    Service Flags:                      0x20609
    Protocol Chain Length:              1
    
    Winsock Catalog Provider Entry
    ------------------------------------------------------
    Entry Type:                         Base Service Provider
    Description:                        RSVP TCPv6 Service Provider
    Provider ID:                        {9D60A9E0-337A-11D0-BD88-0000C082E69A}
    Provider Path:                      %SystemRoot%\system32\mswsock.dll
    Catalog Entry ID:                   1007
    Version:                            2
    Address Family:                     23
    Max Address Length:                 28
    Min Address Length:                 28
    Socket Type:                        1
    Protocol:                           6
    Service Flags:                      0x22066
    Protocol Chain Length:              1
    
    Winsock Catalog Provider Entry
    ------------------------------------------------------
    Entry Type:                         Base Service Provider
    Description:                        RSVP TCP Service Provider
    Provider ID:                        {9D60A9E0-337A-11D0-BD88-0000C082E69A}
    Provider Path:                      %SystemRoot%\system32\mswsock.dll
    Catalog Entry ID:                   1008
    Version:                            2
    Address Family:                     2
    Max Address Length:                 16
    Min Address Length:                 16
    Socket Type:                        1
    Protocol:                           6
    Service Flags:                      0x22066
    Protocol Chain Length:              1
    
    Winsock Catalog Provider Entry
    ------------------------------------------------------
    Entry Type:                         Base Service Provider
    Description:                        RSVP UDPv6 Service Provider
    Provider ID:                        {9D60A9E0-337A-11D0-BD88-0000C082E69A}
    Provider Path:                      %SystemRoot%\system32\mswsock.dll
    Catalog Entry ID:                   1009
    Version:                            2
    Address Family:                     23
    Max Address Length:                 28
    Min Address Length:                 28
    Socket Type:                        2
    Protocol:                           17
    Service Flags:                      0x22609
    Protocol Chain Length:              1
    
    Winsock Catalog Provider Entry
    ------------------------------------------------------
    Entry Type:                         Base Service Provider
    Description:                        RSVP UDP Service Provider
    Provider ID:                        {9D60A9E0-337A-11D0-BD88-0000C082E69A}
    Provider Path:                      %SystemRoot%\system32\mswsock.dll
    Catalog Entry ID:                   1010
    Version:                            2
    Address Family:                     2
    Max Address Length:                 16
    Min Address Length:                 16
    Socket Type:                        2
    Protocol:                           17
    Service Flags:                      0x22609
    Protocol Chain Length:              1
    
    Winsock Catalog Provider Entry
    ------------------------------------------------------
    Entry Type:                         Base Service Provider (32)
    Description:                        MSAFD Tcpip [TCP/IP]
    Provider ID:                        {E70F1AA0-AB8B-11CF-8CA3-00805F48A192}
    Provider Path:                      %SystemRoot%\system32\mswsock.dll
    Catalog Entry ID:                   1001
    Version:                            2
    Address Family:                     2
    Max Address Length:                 16
    Min Address Length:                 16
    Socket Type:                        1
    Protocol:                           6
    Service Flags:                      0x20066
    Protocol Chain Length:              1
    
    Winsock Catalog Provider Entry
    ------------------------------------------------------
    Entry Type:                         Base Service Provider (32)
    Description:                        MSAFD Tcpip [UDP/IP]
    Provider ID:                        {E70F1AA0-AB8B-11CF-8CA3-00805F48A192}
    Provider Path:                      %SystemRoot%\system32\mswsock.dll
    Catalog Entry ID:                   1002
    Version:                            2
    Address Family:                     2
    Max Address Length:                 16
    Min Address Length:                 16
    Socket Type:                        2
    Protocol:                           17
    Service Flags:                      0x20609
    Protocol Chain Length:              1
    
    Winsock Catalog Provider Entry
    ------------------------------------------------------
    Entry Type:                         Base Service Provider (32)
    Description:                        MSAFD Tcpip [RAW/IP]
    Provider ID:                        {E70F1AA0-AB8B-11CF-8CA3-00805F48A192}
    Provider Path:                      %SystemRoot%\system32\mswsock.dll
    Catalog Entry ID:                   1003
    Version:                            2
    Address Family:                     2
    Max Address Length:                 16
    Min Address Length:                 16
    Socket Type:                        3
    Protocol:                           0
    Service Flags:                      0x20609
    Protocol Chain Length:              1
    
    Winsock Catalog Provider Entry
    ------------------------------------------------------
    Entry Type:                         Base Service Provider (32)
    Description:                        MSAFD Tcpip [TCP/IPv6]
    Provider ID:                        {F9EAB0C0-26D4-11D0-BBBF-00AA006C34E4}
    Provider Path:                      %SystemRoot%\system32\mswsock.dll
    Catalog Entry ID:                   1004
    Version:                            2
    Address Family:                     23
    Max Address Length:                 28
    Min Address Length:                 28
    Socket Type:                        1
    Protocol:                           6
    Service Flags:                      0x20066
    Protocol Chain Length:              1
    
    Winsock Catalog Provider Entry
    ------------------------------------------------------
    Entry Type:                         Base Service Provider (32)
    Description:                        MSAFD Tcpip [UDP/IPv6]
    Provider ID:                        {F9EAB0C0-26D4-11D0-BBBF-00AA006C34E4}
    Provider Path:                      %SystemRoot%\system32\mswsock.dll
    Catalog Entry ID:                   1005
    Version:                            2
    Address Family:                     23
    Max Address Length:                 28
    Min Address Length:                 28
    Socket Type:                        2
    Protocol:                           17
    Service Flags:                      0x20609
    Protocol Chain Length:              1
    
    Winsock Catalog Provider Entry
    ------------------------------------------------------
    Entry Type:                         Base Service Provider (32)
    Description:                        MSAFD Tcpip [RAW/IPv6]
    Provider ID:                        {F9EAB0C0-26D4-11D0-BBBF-00AA006C34E4}
    Provider Path:                      %SystemRoot%\system32\mswsock.dll
    Catalog Entry ID:                   1006
    Version:                            2
    Address Family:                     23
    Max Address Length:                 28
    Min Address Length:                 28
    Socket Type:                        3
    Protocol:                           0
    Service Flags:                      0x20609
    Protocol Chain Length:              1
    
    Winsock Catalog Provider Entry
    ------------------------------------------------------
    Entry Type:                         Base Service Provider (32)
    Description:                        RSVP TCPv6 Service Provider
    Provider ID:                        {9D60A9E0-337A-11D0-BD88-0000C082E69A}
    Provider Path:                      %SystemRoot%\system32\mswsock.dll
    Catalog Entry ID:                   1007
    Version:                            2
    Address Family:                     23
    Max Address Length:                 28
    Min Address Length:                 28
    Socket Type:                        1
    Protocol:                           6
    Service Flags:                      0x22066
    Protocol Chain Length:              1
    
    Winsock Catalog Provider Entry
    ------------------------------------------------------
    Entry Type:                         Base Service Provider (32)
    Description:                        RSVP TCP Service Provider
    Provider ID:                        {9D60A9E0-337A-11D0-BD88-0000C082E69A}
    Provider Path:                      %SystemRoot%\system32\mswsock.dll
    Catalog Entry ID:                   1008
    Version:                            2
    Address Family:                     2
    Max Address Length:                 16
    Min Address Length:                 16
    Socket Type:                        1
    Protocol:                           6
    Service Flags:                      0x22066
    Protocol Chain Length:              1
    
    Winsock Catalog Provider Entry
    ------------------------------------------------------
    Entry Type:                         Base Service Provider (32)
    Description:                        RSVP UDPv6 Service Provider
    Provider ID:                        {9D60A9E0-337A-11D0-BD88-0000C082E69A}
    Provider Path:                      %SystemRoot%\system32\mswsock.dll
    Catalog Entry ID:                   1009
    Version:                            2
    Address Family:                     23
    Max Address Length:                 28
    Min Address Length:                 28
    Socket Type:                        2
    Protocol:                           17
    Service Flags:                      0x22609
    Protocol Chain Length:              1
    
    Winsock Catalog Provider Entry
    ------------------------------------------------------
    Entry Type:                         Base Service Provider (32)
    Description:                        RSVP UDP Service Provider
    Provider ID:                        {9D60A9E0-337A-11D0-BD88-0000C082E69A}
    Provider Path:                      %SystemRoot%\system32\mswsock.dll
    Catalog Entry ID:                   1010
    Version:                            2
    Address Family:                     2
    Max Address Length:                 16
    Min Address Length:                 16
    Socket Type:                        2
    Protocol:                           17
    Service Flags:                      0x22609
    Protocol Chain Length:              1
    
    Name Space Provider Entry
    ------------------------------------------------------
    Description:                        Network Location Awareness Legacy (NLAv1) Namespace
    Provider ID:                        {6642243A-3BA8-4AA6-BAA5-2E0BD71FDD83}
    Name Space:                         15
    Active:                             1
    Version:                            0
    
    
    Name Space Provider Entry
    ------------------------------------------------------
    Description:                        E-mail Naming Shim Provider
    Provider ID:                        {964ACBA2-B2BC-40EB-8C6A-A6DB40161CAE}
    Name Space:                         37
    Active:                             1
    Version:                            0
    
    
    Name Space Provider Entry
    ------------------------------------------------------
    Description:                        PNRP Cloud Namespace Provider
    Provider ID:                        {03FE89CE-766D-4976-B9C1-BB9BC42C7B4D}
    Name Space:                         39
    Active:                             1
    Version:                            0
    
    
    Name Space Provider Entry
    ------------------------------------------------------
    Description:                        PNRP Name Namespace Provider
    Provider ID:                        {03FE89CD-766D-4976-B9C1-BB9BC42C7B4D}
    Name Space:                         38
    Active:                             1
    Version:                            0
    
    
    Name Space Provider Entry
    ------------------------------------------------------
    Description:                        Tcpip
    Provider ID:                        {22059D40-7E9E-11CF-AE5A-00AA00A7112B}
    Name Space:                         12
    Active:                             1
    Version:                            0
    
    
    Name Space Provider Entry
    ------------------------------------------------------
    Description:                        NTDS
    Provider ID:                        {3B2637EE-E580-11CF-A555-00C04FD8D4AC}
    Name Space:                         32
    Active:                             1
    Version:                            0
    
    
    Name Space Provider Entry
    ------------------------------------------------------
    Description:                        WindowsLive NSP
    Provider ID:                        {4177DDE9-6028-479E-B7B7-03591A63FF3A}
    Name Space:                         12
    Active:                             1
    Version:                            1
    
    
    Name Space Provider Entry
    ------------------------------------------------------
    Description:                        WindowsLive Local NSP
    Provider ID:                        {229F2A2C-5F18-4A06-8F89-3A372170624D}
    Name Space:                         19
    Active:                             1
    Version:                            1
    
    
    Name Space Provider Entry (32)
    ------------------------------------------------------
    Description:                        Network Location Awareness Legacy (NLAv1) Namespace
    Provider ID:                        {6642243A-3BA8-4AA6-BAA5-2E0BD71FDD83}
    Name Space:                         15
    Active:                             1
    Version:                            0
    
    
    Name Space Provider Entry (32)
    ------------------------------------------------------
    Description:                        E-mail Naming Shim Provider
    Provider ID:                        {964ACBA2-B2BC-40EB-8C6A-A6DB40161CAE}
    Name Space:                         37
    Active:                             1
    Version:                            0
    
    
    Name Space Provider Entry (32)
    ------------------------------------------------------
    Description:                        PNRP Cloud Namespace Provider
    Provider ID:                        {03FE89CE-766D-4976-B9C1-BB9BC42C7B4D}
    Name Space:                         39
    Active:                             1
    Version:                            0
    
    
    Name Space Provider Entry (32)
    ------------------------------------------------------
    Description:                        PNRP Name Namespace Provider
    Provider ID:                        {03FE89CD-766D-4976-B9C1-BB9BC42C7B4D}
    Name Space:                         38
    Active:                             1
    Version:                            0
    
    
    Name Space Provider Entry (32)
    ------------------------------------------------------
    Description:                        Tcpip
    Provider ID:                        {22059D40-7E9E-11CF-AE5A-00AA00A7112B}
    Name Space:                         12
    Active:                             1
    Version:                            0
    
    
    Name Space Provider Entry (32)
    ------------------------------------------------------
    Description:                        NTDS
    Provider ID:                        {3B2637EE-E580-11CF-A555-00C04FD8D4AC}
    Name Space:                         32
    Active:                             1
    Version:                            0
    
    
    Name Space Provider Entry (32)
    ------------------------------------------------------
    Description:                        WindowsLive NSP
    Provider ID:                        {4177DDE9-6028-479E-B7B7-03591A63FF3A}
    Name Space:                         12
    Active:                             1
    Version:                            1
    
    
    Name Space Provider Entry (32)
    ------------------------------------------------------
    Description:                        WindowsLive Local NSP
    Provider ID:                        {229F2A2C-5F18-4A06-8F89-3A372170624D}
    Name Space:                         19
    Active:                             1
    Version:                            1
    

    【讨论】:

    • “服务标志”0x20000 位已清除(未设置)是什么意思?它是什么样子的?谢谢
    【解决方案2】:

    这里理解问题的关键是提供程序,在您的情况下它是“SSL 提供程序”,主要问题是连接超时。如果问题与“TCP Provider”有关,则可能有几个与网络等相关的原因,但在您的情况下,这是连接框架内的安全相关问题。

    调查此问题的下一步是,在同一台机器上,您可以从 SSMS 连接到同一个 SQL 数据库,但不能从 IIS 连接,这意味着 IIS 应用程序进程无法获得正确的证书来创建 SSL 隧道来创建连接成功。您可能有一些写入系统事件日志的日志,因此请检查那里。

    因为您使用的是实体框架并且依赖于 EF 版本,所以连接字符串中存在一些更改,因此请验证您是否拥有:

    <add name="MyDatabaseModelEntities" connectionString="metadata=res://*/MyDBModel.csdl|res://*/MyDatabaseModel.ssdl|res://*/MyDatabaseModel.msl;provider=System.Data.SqlClient;provider connection string="data source=abcdefg123.database.windows.net;initial catalog=MyDatabase;persist security info=True;user id=MyDatabaseUser@abcdefg123;password=p@$$w0rd;multipleactiveresultsets=True;Trusted_Connection=False;Encrypt=True;App=EntityFramework"" providerName="System.Data.EntityClient" /> 
    

    最后,如果您使用的是 EF 4.3.1 并连接到 SQL 数据库,请查看this 文章并检查您是否有类似的配置。

    【讨论】:

    • 感谢您提及安全方面。就我而言,我使用的是 LinqPad,但遇到了这个异常。以管理员身份运行 LinqPad 实例解决了这个问题。以防万一其他人遇到同样的问题...
    【解决方案3】:

    在 microsoft connect 站点 here 中报告了此问题。解决方案可用here。您需要删除非 IFS LSP 安装的 Winsock Catalog Provider。有时您的机器上已经安装了一些软件可能会导致问题。为了删除非 IFS LSP,首先在命令提示符下运行以下命令以查看导致问题的应用程序 (ref)

    netsh winsock show catalog > LSP.txt
    

    查看输出并分析导致问题的应用程序并将其卸载。希望它能解决问题。

    【讨论】:

    • 运行此命令的 IIRC 给了我一个巨大的命令行信息列表,如果没有进一步的说明,这些信息是无用的。您是绝对正确的,这正是问题所在,但是如果您不知道如何解析信息,则运行此命令将毫无用处。出于某种原因,这个问题很受欢迎。如果您有更多关于非 IFS LSP 安装的 winsock 目录提供程序以及如何使用提供的命令提供的信息的信息,那就太好了。
    • 只看文本文件,看看安装的程序,看看罪魁祸首
    【解决方案4】:

    在我的情况下,在尝试修复我的 VS2012RC 几次但没有运气后,我偶然发现了 this link,其中一个 cmets 与名为“sendori”的第三方软件有关。我卸载了它,我的世界一切都恢复正常了。

    【讨论】:

      【解决方案5】:

      还有一个提示: SQL 服务器可能内存不足。我遇到了这个错误,当我检查 SQL 服务器计算机时,SQL 服务使用了 15G 内存,总共 16 个。所以重启服务来修复。

      【讨论】:

      • 数据库有多大? SQL Server 通常会消耗尽可能多的内存,而不会导致操作系统出现不良行为。
      【解决方案6】:

      问题最终是 vs11 测试版。

      如果您遇到此问题,您需要执行以下操作:

      1) 卸载 vs11 beta 和 .NET 4.5 beta

      2) 重新安装 .NET 4.0

      再次观察一切正常!

      【讨论】:

      • 这不是正确的解决方案。这忽略了系统上的其他应用程序没有使用正确协议的真正问题。
      【解决方案7】:

      我在 SSMS 2012 上遇到了同样的问题,但在 SSMS 2008 上,在连接到同一个远程服务器的同一个盒子上一切正常。

      Moca.io 代理给我带来了麻烦。已卸载,现在一切正常。 ("移除非 IFS LSP")

      【讨论】:

        【解决方案8】:

        有同样的问题。 就我而言,卸载 T-Mobile Web 'n Walk Manager 解决了问题。 它的软件通过 sim 卡进行移动连接到互联网 约西普

        【讨论】:

          【解决方案9】:

          我有这个确切的错误。通过设置服务器不是XXXXXXXXX而是全域名XXXXXXXXX.YYY.com来解决

          然后出现一条消息说不支持加密连接。

          当我一切正常时。

          【讨论】:

          • 你能澄清一下我通过谷歌搜索我的错误发现这个页面的反对票吗?登录前握手期间发生错误。 (提供者:SSL 提供者,错误:0
          【解决方案10】:

          如果您使用点“。”或数据源的服务器部分名称(不含域名),请尝试使用实际的 SQL Server 实例名称和完整的服务器名称。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2012-04-19
            • 2011-07-28
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2018-10-14
            相关资源
            最近更新 更多