.NET 4.5.1 and SqlConnection.Open() = an error occurred during the login process

Windows 7 x64 machines had just been upgraded from .NET 4.0 to .NET 4.5.1 via KB2858728 (http://support.microsoft.com/kb/2858728) which offers the following benefits:

  • Performance and reliability improvements
  • The ability to suspend and resume operations in the ASP.NET page framework
  • The ability to compact large object heaps on-demand
  • 64-bit Edit and Continue controls
  • The ability to trace and sample activities
  • Improvements that make SQL connections more resilient
  • The ability to manage return values

 

After the upgrade it was no longer possible to connect to remote SQL servers using code like this:

using (var conn = new SqlConnection(“<my connection string>”))
{
    conn.Open();
}

 

The conn.Open() started throwing the following exception:

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

The call stack looked like this:

System.Data.dll!System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(System.Data.SqlClient.ServerInfo serverInfo = {unknown}, string newPassword = {unknown}, System.Security.SecureString newSecurePassword = {unknown}, bool redirectedUserInstance = {unknown}, System.Data.SqlClient.SqlConnectionString connectionOptions = {unknown}, System.Data.SqlClient.SqlCredential credential = {unknown}, System.Data.ProviderBase.TimeoutTimer timeout = {unknown}) 

System.Data.dll!System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(System.Data.ProviderBase.TimeoutTimer timeout = {unknown}, System.Data.SqlClient.SqlConnectionString connectionOptions = {unknown}, System.Data.SqlClient.SqlCredential credential = {unknown}, string newPassword = {unknown}, System.Security.SecureString newSecurePassword = {unknown}, bool redirectedUserInstance = {unknown}) 

System.Data.dll!System.Data.SqlClient.SqlInternalConnectionTds..ctor(System.Data.ProviderBase.DbConnectionPoolIdentity identity = {unknown}, System.Data.SqlClient.SqlConnectionString connectionOptions = {unknown}, System.Data.SqlClient.SqlCredential credential = {unknown}, object providerInfo = {unknown}, string newPassword = {unknown}, System.Security.SecureString newSecurePassword = {unknown}, bool redirectedUserInstance = {unknown}, System.Data.SqlClient.SqlConnectionString userConnectionOptions = {unknown}, System.Data.SqlClient.SessionData reconnectSessionData = {unknown}) 

System.Data.dll!System.Data.SqlClient.SqlConnectionFactory.CreateConnection(System.Data.Common.DbConnectionOptions options = {unknown}, System.Data.Common.DbConnectionPoolKey poolKey = {unknown}, object poolGroupProviderInfo = {unknown}, System.Data.ProviderBase.DbConnectionPool pool = {unknown}, System.Data.Common.DbConnection owningConnection = {unknown}, System.Data.Common.DbConnectionOptions userOptions = {unknown})  

System.Data.dll!System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(System.Data.ProviderBase.DbConnectionPool pool = {unknown}, System.Data.Common.DbConnection owningObject = {unknown}, System.Data.Common.DbConnectionOptions options = {unknown}, System.Data.Common.DbConnectionPoolKey poolKey = {unknown}, System.Data.Common.DbConnectionOptions userOptions = {unknown})  

System.Data.dll!System.Data.ProviderBase.DbConnectionPool.CreateObject(System.Data.Common.DbConnection owningObject = {unknown}, System.Data.Common.DbConnectionOptions userOptions = {unknown}, System.Data.ProviderBase.DbConnectionInternal oldConnection = {unknown})     

System.Data.dll!System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(System.Data.Common.DbConnection owningObject = {unknown}, System.Data.Common.DbConnectionOptions userOptions = {unknown}, System.Data.ProviderBase.DbConnectionInternal oldConnection = {unknown})     

System.Data.dll!System.Data.ProviderBase.DbConnectionPool.TryGetConnection(System.Data.Common.DbConnection owningObject = {unknown}, uint waitForMultipleObjectsTimeout = {unknown}, bool allowCreate = {unknown}, bool onlyOneCheckConnection = {unknown}, System.Data.Common.DbConnectionOptions userOptions = {unknown}, out System.Data.ProviderBase.DbConnectionInternal connection = {unknown}) 

System.Data.dll!System.Data.ProviderBase.DbConnectionPool.TryGetConnection(System.Data.Common.DbConnection owningObject = {unknown}, System.Threading.Tasks.TaskCompletionSource<System.Data.ProviderBase.DbConnectionInternal> retry = {unknown}, System.Data.Common.DbConnectionOptions userOptions = {unknown}, out System.Data.ProviderBase.DbConnectionInternal connection = {unknown})  

System.Data.dll!System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(System.Data.Common.DbConnection owningConnection = {unknown}, System.Threading.Tasks.TaskCompletionSource<System.Data.ProviderBase.DbConnectionInternal> retry = {unknown}, System.Data.Common.DbConnectionOptions userOptions = {unknown}, System.Data.ProviderBase.DbConnectionInternal oldConnection = {unknown}, out System.Data.ProviderBase.DbConnectionInternal connection = {unknown})  

System.Data.dll!System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(System.Data.Common.DbConnection outerConnection = {unknown}, System.Data.ProviderBase.DbConnectionFactory connectionFactory = {unknown}, System.Threading.Tasks.TaskCompletionSource<System.Data.ProviderBase.DbConnectionInternal> retry = {unknown}, System.Data.Common.DbConnectionOptions userOptions = {unknown}) 

System.Data.dll!System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(System.Data.Common.DbConnection outerConnection = {unknown}, System.Data.ProviderBase.DbConnectionFactory connectionFactory = {unknown}, System.Threading.Tasks.TaskCompletionSource<System.Data.ProviderBase.DbConnectionInternal> retry = {unknown}, System.Data.Common.DbConnectionOptions userOptions = {unknown}) 

System.Data.dll!System.Data.SqlClient.SqlConnection.TryOpenInner(System.Threading.Tasks.TaskCompletionSource<System.Data.ProviderBase.DbConnectionInternal> retry = {unknown})     

System.Data.dll!System.Data.SqlClient.SqlConnection.TryOpen(System.Threading.Tasks.TaskCompletionSource<System.Data.ProviderBase.DbConnectionInternal> retry = {unknown})     

     System.Data.dll!System.Data.SqlClient.SqlConnection.Open() 

 

.NET 2.0 or NET 3.5 applications were not affected, only those targeting .NET 4.0. A quick workaround was to reset the Winsock catalog to a clean state:

netsh winsock reset

Note: All Winsock Layered Service Providers (LSPs) which were previously installed must be reinstalled. This command does not affect Winsock Name Space Provider entries.

However this workaround was only temporary – as 3rd party program repaired it’s LSPs the issue returned.

To find the provider at fault we listed all installed providers with command

netsh winsock show catalog

 

This provided the following output:

Winsock Catalog Provider Entry
——————————————————
Entry Type:                         Layered Chain Entry
Description:                        Sophos Web Intelligence LSP over [MSAFD Tcpip [TCP/IP]]
Provider ID:                        {F9C047C7-FADC-42A0-90AE-078C7315BC69}
Provider Path:                      C:\ProgramData\Sophos Web Intelligence\swi_lsp_64.dll
Catalog Entry ID:                   1013
Version:                            2
Address Family:                     2
Max Address Length:                 16
Min Address Length:                 16
Socket Type:                        1
Protocol:                           6
Service Flags:                      0x66
Protocol Chain Length:              2
Protocol Chain: 1011 : 1001

Winsock Catalog Provider Entry
——————————————————
Entry Type:                         Layered Chain Entry
Description:                        Sophos Web Intelligence LSP over [MSAFD Tcpip [UDP/IP]]
Provider ID:                        {B2E091CB-AB6F-4F98-B035-989156056E11}
Provider Path:                      C:\ProgramData\Sophos Web Intelligence\swi_lsp_64.dll
Catalog Entry ID:                   1014
Version:                            2
Address Family:                     2
Max Address Length:                 16
Min Address Length:                 16
Socket Type:                        2
Protocol:                           17
Service Flags:                      0x609
Protocol Chain Length:              2
Protocol Chain: 1011 : 1002

Winsock Catalog Provider Entry
——————————————————
Entry Type:                         Layered Chain Entry
Description:                        Sophos Web Intelligence LSP over [MSAFD Tcpip [TCP/IPv6]]
Provider ID:                        {71B909D0-BF67-4AF0-8140-C4E47594A7C2}
Provider Path:                      C:\ProgramData\Sophos Web Intelligence\swi_lsp_64.dll
Catalog Entry ID:                   1015
Version:                            2
Address Family:                     23
Max Address Length:                 28
Min Address Length:                 28
Socket Type:                        1
Protocol:                           6
Service Flags:                      0x66
Protocol Chain Length:              2
Protocol Chain: 1011 : 1004

Winsock Catalog Provider Entry
——————————————————
Entry Type:                         Layered Chain Entry
Description:                        Sophos Web Intelligence LSP over [MSAFD Tcpip [UDP/IPv6]]
Provider ID:                        {24FA2D3C-9977-4E79-9B3A-1B00A42ABB09}
Provider Path:                      C:\ProgramData\Sophos Web Intelligence\swi_lsp_64.dll
Catalog Entry ID:                   1016
Version:                            2
Address Family:                     23
Max Address Length:                 28
Min Address Length:                 28
Socket Type:                        2
Protocol:                           17
Service Flags:                      0x609
Protocol Chain Length:              2
Protocol Chain: 1011 : 1005

Winsock Catalog Provider Entry
——————————————————
Entry Type:                         Layered Chain Entry
Description:                        Sophos Web Intelligence LSP over [RSVP TCPv6 Service Provider]
Provider ID:                        {4D9EB2FF-D675-49E7-B6F7-F10B3D7373B0}
Provider Path:                      C:\ProgramData\Sophos Web Intelligence\swi_lsp_64.dll
Catalog Entry ID:                   1017
Version:                            2
Address Family:                     23
Max Address Length:                 28
Min Address Length:                 28
Socket Type:                        1
Protocol:                           6
Service Flags:                      0x2066
Protocol Chain Length:              2
Protocol Chain: 1011 : 1007

Winsock Catalog Provider Entry
——————————————————
Entry Type:                         Layered Chain Entry
Description:                        Sophos Web Intelligence LSP over [RSVP TCP Service Provider]
Provider ID:                        {C033EAC6-EB01-4382-B011-ADDEAE64D85C}
Provider Path:                      C:\ProgramData\Sophos Web Intelligence\swi_lsp_64.dll
Catalog Entry ID:                   1018
Version:                            2
Address Family:                     2
Max Address Length:                 16
Min Address Length:                 16
Socket Type:                        1
Protocol:                           6
Service Flags:                      0x2066
Protocol Chain Length:              2
Protocol Chain: 1011 : 1008

Winsock Catalog Provider Entry
——————————————————
Entry Type:                         Layered Chain Entry
Description:                        Sophos Web Intelligence LSP over [RSVP UDPv6 Service Provider]
Provider ID:                        {4A94DB27-6A7A-43D5-9CFC-E31B1084A271}
Provider Path:                      C:\ProgramData\Sophos Web Intelligence\swi_lsp_64.dll
Catalog Entry ID:                   1019
Version:                            2
Address Family:                     23
Max Address Length:                 28
Min Address Length:                 28
Socket Type:                        2
Protocol:                           17
Service Flags:                      0x2609
Protocol Chain Length:              2
Protocol Chain: 1011 : 1009

Winsock Catalog Provider Entry
——————————————————
Entry Type:                         Layered Chain Entry
Description:                        Sophos Web Intelligence LSP over [RSVP UDP Service Provider]
Provider ID:                        {7E4D08FF-5C59-494A-9C95-5BA057E88660}
Provider Path:                      C:\ProgramData\Sophos Web Intelligence\swi_lsp_64.dll
Catalog Entry ID:                   1020
Version:                            2
Address Family:                     2
Max Address Length:                 16
Min Address Length:                 16
Socket Type:                        2
Protocol:                           17
Service Flags:                      0x2609
Protocol Chain Length:              2
Protocol Chain: 1011 : 1010

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:                         Layered Service Provider
Description:                        Sophos Web Intelligence LSP
Provider ID:                        {8BFC85A0-09DF-4E9D-8C89-DC87DA833CC8}
Provider Path:                      C:\ProgramData\Sophos Web Intelligence\swi_lsp_64.dll
Catalog Entry ID:                   1011
Version:                            2
Address Family:                     2
Max Address Length:                 16
Min Address Length:                 16
Socket Type:                        0
Protocol:                           0
Service Flags:                      0x66
Protocol Chain Length:              0

Winsock Catalog Provider Entry
——————————————————
Entry Type:                         Layered Chain Entry (32)
Description:                        Sophos Web Intelligence LSP over [MSAFD Tcpip [TCP/IP]]
Provider ID:                        {39745C7F-E028-4E95-8B97-2A94500BDBE7}
Provider Path:                      C:\ProgramData\Sophos Web Intelligence\swi_lsp.dll
Catalog Entry ID:                   1021
Version:                            2
Address Family:                     2
Max Address Length:                 16
Min Address Length:                 16
Socket Type:                        1
Protocol:                           6
Service Flags:                      0x66
Protocol Chain Length:              2
Protocol Chain: 1012 : 1001

Winsock Catalog Provider Entry
——————————————————
Entry Type:                         Layered Chain Entry (32)
Description:                        Sophos Web Intelligence LSP over [MSAFD Tcpip [UDP/IP]]
Provider ID:                        {FED72BC6-20D5-432F-A8FA-AB4B7530552E}
Provider Path:                      C:\ProgramData\Sophos Web Intelligence\swi_lsp.dll
Catalog Entry ID:                   1022
Version:                            2
Address Family:                     2
Max Address Length:                 16
Min Address Length:                 16
Socket Type:                        2
Protocol:                           17
Service Flags:                      0x609
Protocol Chain Length:              2
Protocol Chain: 1012 : 1002

Winsock Catalog Provider Entry
——————————————————
Entry Type:                         Layered Chain Entry (32)
Description:                        Sophos Web Intelligence LSP over [MSAFD Tcpip [TCP/IPv6]]
Provider ID:                        {7B1C62BF-7D03-4216-A5A8-594D7287063C}
Provider Path:                      C:\ProgramData\Sophos Web Intelligence\swi_lsp.dll
Catalog Entry ID:                   1023
Version:                            2
Address Family:                     23
Max Address Length:                 28
Min Address Length:                 28
Socket Type:                        1
Protocol:                           6
Service Flags:                      0x66
Protocol Chain Length:              2
Protocol Chain: 1012 : 1004

Winsock Catalog Provider Entry
——————————————————
Entry Type:                         Layered Chain Entry (32)
Description:                        Sophos Web Intelligence LSP over [MSAFD Tcpip [UDP/IPv6]]
Provider ID:                        {D150F7F8-0E12-4B53-BF9A-FB492C36917E}
Provider Path:                      C:\ProgramData\Sophos Web Intelligence\swi_lsp.dll
Catalog Entry ID:                   1024
Version:                            2
Address Family:                     23
Max Address Length:                 28
Min Address Length:                 28
Socket Type:                        2
Protocol:                           17
Service Flags:                      0x609
Protocol Chain Length:              2
Protocol Chain: 1012 : 1005

Winsock Catalog Provider Entry
——————————————————
Entry Type:                         Layered Chain Entry (32)
Description:                        Sophos Web Intelligence LSP over [RSVP TCPv6 Service Provider]
Provider ID:                        {84128345-9F2A-46DB-AB7F-8DEC9A93F660}
Provider Path:                      C:\ProgramData\Sophos Web Intelligence\swi_lsp.dll
Catalog Entry ID:                   1025
Version:                            2
Address Family:                     23
Max Address Length:                 28
Min Address Length:                 28
Socket Type:                        1
Protocol:                           6
Service Flags:                      0x2066
Protocol Chain Length:              2
Protocol Chain: 1012 : 1007

Winsock Catalog Provider Entry
——————————————————
Entry Type:                         Layered Chain Entry (32)
Description:                        Sophos Web Intelligence LSP over [RSVP TCP Service Provider]
Provider ID:                        {E4DFA87C-B750-4735-A35F-A60F33EC98CC}
Provider Path:                      C:\ProgramData\Sophos Web Intelligence\swi_lsp.dll
Catalog Entry ID:                   1026
Version:                            2
Address Family:                     2
Max Address Length:                 16
Min Address Length:                 16
Socket Type:                        1
Protocol:                           6
Service Flags:                      0x2066
Protocol Chain Length:              2
Protocol Chain: 1012 : 1008

Winsock Catalog Provider Entry
——————————————————
Entry Type:                         Layered Chain Entry (32)
Description:                        Sophos Web Intelligence LSP over [RSVP UDPv6 Service Provider]
Provider ID:                        {967D92B8-44E0-487B-8187-0CE634565A9D}
Provider Path:                      C:\ProgramData\Sophos Web Intelligence\swi_lsp.dll
Catalog Entry ID:                   1027
Version:                            2
Address Family:                     23
Max Address Length:                 28
Min Address Length:                 28
Socket Type:                        2
Protocol:                           17
Service Flags:                      0x2609
Protocol Chain Length:              2
Protocol Chain: 1012 : 1009

Winsock Catalog Provider Entry
——————————————————
Entry Type:                         Layered Chain Entry (32)
Description:                        Sophos Web Intelligence LSP over [RSVP UDP Service Provider]
Provider ID:                        {060CA60F-4D41-4B7D-9DCF-EACC385F3639}
Provider Path:                      C:\ProgramData\Sophos Web Intelligence\swi_lsp.dll
Catalog Entry ID:                   1028
Version:                            2
Address Family:                     2
Max Address Length:                 16
Min Address Length:                 16
Socket Type:                        2
Protocol:                           17
Service Flags:                      0x2609
Protocol Chain Length:              2
Protocol Chain: 1012 : 1010

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

Winsock Catalog Provider Entry
——————————————————
Entry Type:                         Layered Service Provider (32)
Description:                        Sophos Web Intelligence LSP
Provider ID:                        {8BFC85A0-09DF-4E9D-8C89-DC87DA833CC8}
Provider Path:                      C:\ProgramData\Sophos Web Intelligence\swi_lsp.dll
Catalog Entry ID:                   1012
Version:                            2
Address Family:                     2
Max Address Length:                 16
Min Address Length:                 16
Socket Type:                        0
Protocol:                           0
Service Flags:                      0x66
Protocol Chain Length:              0

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 (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

 

From this we can find our culprit – The only 3rd party providers installed here are all from Sophos. Uninstalling Sophos fixed the issue – however being the firewall / anti-virus software on the machine that was not a permanent solution. We could also fix the issue by uninstalling .NET 4.5.1 and re-installing .NET 4.0 and 4.5 would resolve the issue.

This is documented in Microsoft KB article “Applications crash and “AccessViolationException” exception occurs when you use System.Data.SqlClient after you install Visual Studio 2013 or .NET Framework 4.5.1” http://support.microsoft.com/kb/2915689 

Which is also listed as known issues for .NET Framework 4.5.1 http://support.microsoft.com/kb/2890857 

As per the article :

This problem occurs because some non-IFS Winsock Base Service Providers (BSPs) or Layered Service Providers (LSPs) that are installed on the system intercept and change the incoming and outgoing network traffic. Therefore, when the application connects to SQL Server, these BSPs or LSPs interfere with the calls to Winsock

1.    If the Service Flags value has the 0x20000 bit set, this indicates that the provider uses IFS handles and works correctly.
2.    If the 0x20000 bit is clear (not set), this indicates that the provider is a non-IFS BSP or LSP.

We can straight away see that the following LSP doesn’t have this bit set:

Entry Type:                         Layered Chain Entry
Description:                        Sophos Web Intelligence LSP over [MSAFD Tcpip [TCP/IP]]
Provider ID:                        {F9C047C7-FADC-42A0-90AE-078C7315BC69}
Provider Path:                      C:\ProgramData\Sophos Web Intelligence\swi_lsp_64.dll
Catalog Entry ID:                   1013
Version:                            2
Address Family:                     2
Max Address Length:                 16
Min Address Length:                 16
Socket Type:                        1
Protocol:                           6
Service Flags:                      0x66
Protocol Chain Length:              2
Protocol Chain: 1011 : 1001

 

To resolve this issue you will need to remove the non-IFS compliant LSPs, or disable the relevant component in the application that installed it. If you need to keep the LSP you will need vendor to make it IFS compliant, or revert to older .NET framework patch level.

LSPs are a DLL that use Winsock APIs to insert themselves into the TCP/IP stack. Once in the stack they can modify inbound/outbound internet traffic and are commonly used by software to filter web traffic or implement parental controls, or by malware to block Windows Updates :)

Non-IFS LSPs are the most common type currently in use. non-IFS LSPs modify the socket handle to a non valid Windows IFS handle and therefore the LSP must implement all Winsock 2 methods. IFS LSPs, on the other hand, preserve the socket handle, which allows the LSP to implement only the functions it wants to intercept.

Further reading:

Understand the Mysteries of Writing a Winsock 2 Layered Service Provider

http://www.microsoft.com/msj/0599/layeredservice/layeredservice.aspx

The (new) Trouble with Select and LSPs

http://blogs.msdn.com/b/wndp/archive/2006/07/13/664737.aspx

The Darkside of Winsock (exploiting it)

http://hisown.com/Talks/spi.pdf

IFS vs non IFS LSPs

http://www.komodia.com/KomodiaLSPTypes.pdf

Categorizing Layered Service Providers and Applications

http://msdn.microsoft.com/en-us/library/windows/desktop/bb513664(v=vs.85).aspx

About chentiangemalc

specializes in end-user computing technologies. disclaimer 1) use at your own risk. test any solution in your environment. if you do not understand the impact/consequences of what you're doing please stop, and ask advice from somebody who does. 2) views are my own at the time of posting and do not necessarily represent my current view or the view of my employer and family members/relatives. 3) over the years Microsoft/Citrix/VMWare have given me a few free shirts, pens, paper notebooks/etc. despite these gifts i will try to remain unbiased.
This entry was posted in .NET, Windows 7 and tagged . Bookmark the permalink.

One Response to .NET 4.5.1 and SqlConnection.Open() = an error occurred during the login process

  1. You wrote this more than 2 years ago but it is still actual.

    We are having these errors :
    The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement. This could be because the pre-login handshake failed or the server was unable to respond back in time.

    But only at night, almost never during the day, even though the application connects to the database every minute or so.

    We have followed the same steps and for us, it seems that the problem is related to vSockets STREAM which is part of the vsocklib.dll from VMWare.

    In your opinion, is there a way to make VMWare IFS compliant ?

    Thanks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s