Skip to content

Issue with .net core connecting to Remote Microsoft Sqlserver #43

Closed

Description

@itdeepdive

Environment:

Dot.net Core Version: .net core 2.0.6
Operating System: CentOS Linux release 7.4.1708 (Core)
Sqlserver Hosted on Windows: Microsoft SQL Server 2017 (RTM) - 14.0.1000.169 (X64)

Same Error Exists Using Docker microsoft/dotnet 2.0

Error:

Application startup exception: System.Data.SqlClient.SqlException (0x80131904): A connection was successfully established with the server, but then an error occurred during the login process. (provider: TCP Provider, error: 35 - An internal exception was caught) ---> System.IO.IOException: Unable to write data to the transport connection: Connection reset by peer. ---> System.Net.Sockets.SocketException: Connection reset by peer

   at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)
   --- End of inner exception stack trace ---
   at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)
   at System.Data.SqlClient.SNI.SslOverTdsStream.Write(Byte[] buffer, Int32 offset, Int32 count)
   at System.Net.Security.SslStreamInternal.StartWriting(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslStreamInternal.ProcessWrite(Byte[] buffer, Int32 offset, Int32 count, LazyAsyncResult asyncResult)
   at System.Net.Security.SslStream.Write(Byte[] buffer, Int32 offset, Int32 count)
   at System.Data.SqlClient.SNI.SNITCPHandle.Send(SNIPacket packet)
   at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling)
   at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   at System.Data.SqlClient.SqlConnection.Open()
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(Boolean errorsExpected)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.BufferlessMoveNext(Boolean buffer)
   at Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()
   at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.<_TrackEntities>d__17`2.MoveNext()
   at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()
   at System.Collections.Generic.List`1.AddEnumerable(IEnumerable`1 enumerable)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Example.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env) in /tmp/em3_Example/Example/Startup.cs:line 59
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app)
   at Microsoft.AspNetCore.Hosting.Internal.AutoRequestServicesStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder builder)
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
ClientConnectionId:020ebc45-ac5e-4119-a789-865174be336b
crit: Microsoft.AspNetCore.Hosting.Internal.WebHost[6]
      Application startup exception
System.Data.SqlClient.SqlException (0x80131904): A connection was successfully established with the server, but then an error occurred during the login process. (provider: TCP Provider, error: 35 - An internal exception was caught) ---> System.IO.IOException: Unable to write data to the transport connection: Connection reset by peer. ---> System.Net.Sockets.SocketException: Connection reset by peer
   at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)
   --- End of inner exception stack trace ---
   at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)
   at System.Data.SqlClient.SNI.SslOverTdsStream.Write(Byte[] buffer, Int32 offset, Int32 count)
   at System.Net.Security.SslStreamInternal.StartWriting(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslStreamInternal.ProcessWrite(Byte[] buffer, Int32 offset, Int32 count, LazyAsyncResult asyncResult)
   at System.Net.Security.SslStream.Write(Byte[] buffer, Int32 offset, Int32 count)
   at System.Data.SqlClient.SNI.SNITCPHandle.Send(SNIPacket packet)
   at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling)
   at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   at System.Data.SqlClient.SqlConnection.Open()
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(Boolean errorsExpected)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.BufferlessMoveNext(Boolean buffer)
   at Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()
   at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.<_TrackEntities>d__17`2.MoveNext()
   at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()
   at System.Collections.Generic.List`1.AddEnumerable(IEnumerable`1 enumerable)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Example.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env) in /tmp/em3_Example/Example/Startup.cs:line 59
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app)
   at Microsoft.AspNetCore.Hosting.Internal.AutoRequestServicesStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder builder)
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
ClientConnectionId:020ebc45-ac5e-4119-a789-865174be336b

Unhandled Exception: System.Data.SqlClient.SqlException: A connection was successfully established with the server, but then an error occurred during the login process. (provider: TCP Provider, error: 35 - An internal exception was caught) ---> System.IO.IOException: Unable to write data to the transport connection: Connection reset by peer. ---> System.Net.Sockets.SocketException: Connection reset by peer
   at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)
   --- End of inner exception stack trace ---
   at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)
   at System.Data.SqlClient.SNI.SslOverTdsStream.Write(Byte[] buffer, Int32 offset, Int32 count)
   at System.Net.Security.SslStreamInternal.StartWriting(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslStreamInternal.ProcessWrite(Byte[] buffer, Int32 offset, Int32 count, LazyAsyncResult asyncResult)
   at System.Net.Security.SslStream.Write(Byte[] buffer, Int32 offset, Int32 count)
   at System.Data.SqlClient.SNI.SNITCPHandle.Send(SNIPacket packet)
   --- End of inner exception stack trace ---
   at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling)
   at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   at System.Data.SqlClient.SqlConnection.Open()
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(Boolean errorsExpected)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.BufferlessMoveNext(Boolean buffer)
   at Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()
   at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.<_TrackEntities>d__17`2.MoveNext()
   at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()
   at System.Collections.Generic.List`1.AddEnumerable(IEnumerable`1 enumerable)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Example.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env) in /tmp/em3_Example/Example/Startup.cs:line 59
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app)
   at Microsoft.AspNetCore.Hosting.Internal.AutoRequestServicesStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder builder)
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
   at Example.Program.Main(String[] args) in /tmp/em3_Example/Example/Program.cs:line 18
Aborted

[EDIT] Fix exception formatting by @karelz

Activity

  1. karelz commented on May 10, 2018

    @karelz
    Member

    How often does it happen? Is it 100% repro or intermittent?
    Does it happen right away, or after some time?
    Did you do additional network tracing on client and/or server to confirm it is not server closing the connection?

  2. karelz commented on May 10, 2018

    @karelz
    Member

    Could you try .NET Core 2.1 RC? (released earlier this week as "go-live")

  3. akasianenko commented on May 11, 2018

    @akasianenko

    Have just tried .NET Core 2.1 RC (dotnet:2.1-aspnetcore-runtime) and got the same error. Reproduces permanently. The very same connection string from non-core dotnet windows application works fine.
    SQL Server in question is 2016 SP1, and for SQL Server 2014 SP2 connection works just fine.
    I would really appreciate any ideas, thanks.

  4. itdeepdive commented on May 13, 2018

    @itdeepdive
    Author

    @karelz This Happens all the time. I tested it through 2.1.0-rc1-final.

    I get the exact same error.

    Thanks
    Trilok

  5. MaksymProkopiv commented on May 14, 2018

    @MaksymProkopiv

    We tested on .NET Core 2.0.6 and 2.1 RC with the same results:
    [Exception] SQL Server 2008 (SP1) - 10.0.2710.0 (X64)
    [OK] SQL Server 2014 - 12.0.2000.8 (X64)
    [OK] SQL Server 2014 (SP2) (KB3171021) - 12.0.5000.0 (X64)
    [Exception] SQL Server 2014 (SP2-CU8) (KB4037356) - 12.0.5557.0 (X64)
    [Exception] SQL Server 2014 (SP2-CU10-GDR) (KB4052725) - 12.0.5571.0 (X64)
    [Exception] SQL Server 2016 (SP1) (KB3182545) - 13.0.4001.0 (X64)

  6. karelz commented on May 14, 2018

    @karelz
    Member

    Do you have a repro you can share with us?
    Did you try to look at network traces? (Fiddler, Wireshark)

    @keeratsingh @David-Engel @afsanehr any ideas?

  7. self-assigned this
    on May 15, 2018
  8. AfsanehR-zz commented on May 15, 2018

    @AfsanehR-zz

    Hi @itdeepdive , will start investigating this and will update you with more updates here. Thanks!

  9. logankp commented on Jun 4, 2018

    @logankp

    I also recently started experiencing this issue. It only seems to happen in Linux containers for me. Works just fine using .Net Core on Windows.

  10. EltonCarreiro commented on Jun 4, 2018

    @EltonCarreiro

    The same happens here as @logankp described.

  11. AfsanehR-zz commented on Jun 5, 2018

    @AfsanehR-zz

    @EltonCarreiro and @logankp thank you for confirming this issue.
    I just successfully ran a sample application to read data from a remote SQL Server on my Windows machine from an application on a CentOS machine.

    # dotnet --info
    .NET Core SDK (reflecting any global.json):
     Version:   2.1.300
     Commit:    adab45bf0c
    
    Runtime Environment:
     OS Name:     centos
     OS Version:  7
     OS Platform: Linux
     RID:         centos.7-x64
     Base Path:   /root/dotnet/sdk/2.1.300/
    
    Host (useful for support):
      Version: 2.1.0
      Commit:  caa7b7e2ba
    
    .NET Core SDKs installed:
      2.1.300 [/root/dotnet/sdk]
    
    .NET Core runtimes installed:
      Microsoft.AspNetCore.All 2.1.0 [/root/dotnet/shared/Microsoft.AspNetCore.All]
      Microsoft.AspNetCore.App 2.1.0 [/root/dotnet/shared/Microsoft.AspNetCore.App]
      Microsoft.NETCore.App 2.1.0 [/root/dotnet/shared/Microsoft.NETCore.App]
    
    To install additional .NET Core runtimes or SDKs:
      https://aka.ms/dotnet-download
    
    

    Although I had to download the dotnet-sdk-2.1, since using package manager I am getting issues as mentioned on this Github Issue

    As @karelz mentioned, do you see this happening right away of after some time? A repro would be helpful to better investigate the issue. Thanks.

  12. EltonCarreiro commented on Jun 5, 2018

    @EltonCarreiro

    @afsanehr thank you for the quick response.

    The application is deployed as SCD (using 2.0.6), so I don't have the SDK installed on my Linux server (I don't know if it can change something).

    Another difference is that my app is hosted on an Linux Ubuntu 16.04.2 LTS

    dotnet --info
    
    Microsoft .NET Core Shared Framework Host
    
      Version  : 2.0.5
      Build    : 17373eb129b3b05aa18ece963f8795d65ef8ea54
    

    The exception is thrown according to the timeout specified in the connection string, so if I specify 30 seconds, that's the time it takes.

    My problem occur exactly when I try to connect to the SQL Server, so the code doesn't have anything different.

    public IDbConnection CreateNewConnection()
    {
        return new SqlConnection(Configuration["ConnectionStrings:SQLServerDP"]); // throws
    }

    And as you might expect, at my appsettings.json I have the connectionstring

    "ConnectionStrings": {
            "SQLServerDP": "Data Source={SERVER HERE}\\{INSTANCE HERE};Initial Catalog={CATALOG NAME HERE};User ID={USER HERE};Password={PASSWD HERE};Max Pool Size=1000;Connect Timeout=300;"
    }

    So, as we can see, according to the above connectionstring, it will take 300 seconds to throw the exception.

    If you still want a reproduction please let me know and I'll send one ASAP.

  13. logankp commented on Jun 5, 2018

    @logankp

    This issue is a bit challenging for me to reproduce: it occurs when connecting to SQL Server 2014 (12.0.5207.0) on one server only (so far) but is consistent. I'm able to connect to a 2017 instance on the same server. I've installed SQL Server 2014 on another machine and it can connect to that just fine.

    I'm using the microsoft/aspnetcore container and I've tried both EF Core 2.0 and 2.1. The issue occurs on both versions of EF.

  14. JanR1 commented on Jun 14, 2018

    @JanR1

    Hello,
    Having the same problem.

    System.Data.SqlClient.SqlException (0x80131904): A connection was successfully established with the server, but then an error occurred during the login process. (provider: TCP Provider, error: 35 - An internal exception was caught) ---> System.IO.IOException: Unable to write data to the transport connection: Connection reset by peer. ---> System.Net.Sockets.SocketException: Connection reset by peer 6/13/2018 5:46:03 PM at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size) 6/13/2018 5:46:03 PM --- End of inner exception stack trace ---

    However - It seems to not be tied with exact version of SQL Server.
    We have 2016 SP1 CU7 (13.0.4466.4) in PROD(Phys Cluster), TEST(VM) and multiple DEV machines (VM).
    Every server works except the TEST (VM).
    However, From the exact same container I was able to successfully connect with SQLCMD.

  15. AfsanehR-zz commented on Jun 14, 2018

    @AfsanehR-zz

    @JanR1 @logankp @EltonCarreiro Thank you all for your responses. At this point, we are unable to repro the issue. Is it possible for you to share the network traces with us?

  16. 46 remaining items

  17. yukiwongky commented on Nov 28, 2019

    @yukiwongky
    Contributor

    @petros-d The netcore side of Microsoft.Data.SqlClient uses the SslStream class perform the server-client handshake. When the CRL is unavailable or cannot be found, the driver gets the RemoteCertificateChainErrors and the AuthenticateAsClient fails. Seems like the hard-fail behavior comes from SslStream and we have no control on that.

  18. petros-d commented on Dec 12, 2019

    @petros-d

    Looking at the constructors for SslStream (https://docs.microsoft.com/en-us/dotnet/api/system.net.security.sslstream.-ctor?view=netcore-2.1) they seem to have a checkCertificateRevocation flag available to use, which sounds like it could be useful in this case.

    Would you be able to expose that flag to users of SqlClient?

  19. jkshan commented on Apr 2, 2020

    @jkshan

    Could be related to #367 (comment)

  20. john-mbone commented on Apr 26, 2020

    @john-mbone

    Was the issue fixed,i am running sql server on docker with asp .net core 3.1
    my applications works fine on windows but when deployed to Ubuntu Server :
    A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 35 - An internal exception was caught)

  21. removed this from the 2.0.0 milestone on Jun 18, 2020
  22. imranmomin commented on Nov 12, 2020

    @imranmomin

    Yesterday - when .NET 5 was released I upgraded my application. I'm facing a similar issue A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - The target principal name is incorrect.).

    When I downgrade to EF Core 3.10.0 it works fine. It only fails when using EF Core 5. After some investigation I found out that EF Core 3.1.10 uses Microsoft.Data.SqlClient 1.1.3.

    And when I upgrade Microsoft.Data.SqlClient to 2.0.0 it start failing with error A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: HTTP Provider, error: 0 - )

    And on v 2.0.1 the error is A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - The target principal name is incorrect.)

    Note: It works fine when connecting to local SQL Server 15.0.2000.5 and fails when it tries to connect a remote SQL Server 12.0.6024.0

    Connection string used - data source=xxx;initial catalog=xxx_db;user id=xxx;password=xxx;

  23. tmaurst commented on Jan 14, 2021

    @tmaurst

    Having to grant my container access to the issuing CA for the SqlServer instance is proving to be a major headache. Exposing checCertificateRevocation to SqlClient as @petros-d mentioned seems solid.

  24. cheenamalhotra commented on Jan 14, 2021

    @cheenamalhotra
    Member
  25. tmaurst commented on Jan 14, 2021

    @tmaurst

    @cheenamalhotra Yes. With both Encrypt=true/false to no effect.

  26. cheenamalhotra commented on Jan 19, 2021

    @cheenamalhotra
    Member

    I was looking more into it today.

    Looking at the constructors for SslStream (https://docs.microsoft.com/en-us/dotnet/api/system.net.security.sslstream.-ctor?view=netcore-2.1) they seem to have a checkCertificateRevocation flag available to use, which sounds like it could be useful in this case.

    Would you be able to expose that flag to users of SqlClient?

    I think you're talking about the CertificateRevocationCheckMode, which if enabled, does not allow revoked certificates to be accepted and this check is enabled by default. This is very important security check and is not configured by our driver, it's left to it's default setting in SslStream. For security reasons, this behavior cannot be configured.

    Client applications must configure trust with server in most secure manner to proceed with SSL authentication.
    Official Guide: Encrypting Connections to SQL Server on Linux

  27. removed
    Up-for-Grabs 🙌
    on Jan 19, 2021
  28. cheenamalhotra commented on Feb 1, 2021

    @cheenamalhotra
    Member

    I'm closing this very generic issue, here, we had published a Troubleshooting Guide that covers most scenarios and their solutions, please use the same or open a new issue with specific use-case and repro conditions.

  29. jez9999 commented on Feb 20, 2023

    @jez9999

    I don't think this should've been closed. I'm getting the following error when trying to connect to a Docker container with SQL server installed:

    A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 35 - An internal exception was caught)
    -->Unable to read data from the transport connection: Connection reset by peer.

    I think the main problem here, and it doesn't seem to have been fixed by MS, is the complete lack of useful log output in this case. Just having SQL Server shut the connection with no logging on either side is ridiculous. There should be a policy of always logging a failed connection attempt and why it failed, or we're just fumbling around in the dark.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions