Repository navigation
Open connection issue on Linux #126
Description
I'm using Microsoft.Data.SqlClient 1.0.19128.1-preview on Linux RHEL 6 to connect to SQLServer running on Windows.
This is my connection string:
string connetionString Server="SomeComputer\SQLIntegTest,61245;Database=db4;uid=user;pwd=password;Trusted_Connection=No"
with this code:
SqlConnection cnn = new SqlConnection(connetionString);
cnn.Open()
I get the following error. The same code works on windows. Any help would be appreciated.
Unhandled Exception: Microsoft.Data.SqlClient.SqlException: Connection Timeout Expired. The timeout period elapsed during the post-login phase. The connection could have timed out while waiting for server to complete the login process and respond; Or it could have timed out while attempting to create multiple active connections. The duration spent while attempting to connect to this server was - [Pre-Login] initialization=118; handshake=271; [Login] initialization=11; authentication=14; [Post-Login] complete=14041; ---> System.ComponentModel.Win32Exception: Unknown error 258
--- End of inner exception stack trace ---
at Microsoft.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling, String accessToken)
at Microsoft.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
at Microsoft.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
at Microsoft.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at Microsoft.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) at Microsoft.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at Microsoft.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) at Microsoft.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 retry)
at Microsoft.Data.SqlClient.SqlConnection.Open()
Abort (core dumped)
Activity
ErikEJ commentedon Jun 13, 2019
That is an odd server name in the connection string, maybe change to:
sjc9999 commentedon Jun 14, 2019
I tried your suggestion same result works on Windows but not Linux.
ErikEJ commentedon Jun 14, 2019
Can you resolve the server name from the Linux box?
sjc9999 commentedon Jun 14, 2019
Yes I use the same connection string with python pyodbc just adding the driver parameter which is not need with c#
sjc9999 commentedon Jun 17, 2019
Well I was testing with SQL Server 2008 and switched to SQL Server 2016 and that works. Interestingly the Windows version of Microsoft.Data.SqlClient with both but the Linux version only works with 2016.
cheenamalhotra commentedon Jul 2, 2019
@sjc1832
Have you checked with SQL Server 2012 by any chance? Since SQL Server 2008 and 2008 R2 are Out of Support, we wouldn't fix the driver to support them. If the issue happens with SQL Server 2012 as well (which is the oldest of supported SQL Servers) we can consider taking a deeper look.
sjc9999 commentedon Jul 19, 2019
I have not checked 2012.
saravananpalanivel commentedon Sep 4, 2019
I'm facing same issue - i.e. my dotnet core 3 preview8 application is running in Kubernetes cluster (on premise Linux container) which is trying to access remote MSSQL Server 2014 - but hung at connection.Open().
But same works with MSSQL Server 2016.
Connection string : "Data Source=10.150.109.140,1433;Initial Catalog=ReportServer;Connect Timeout=60;User ID=username;Password=password; Persist Security Info=False;Packet Size=4096"
Docker images used : mcr.microsoft.com/dotnet/core/sdk:3.0.100-preview8 & mcr.microsoft.com/dotnet/core/aspnet:3.0.0-preview8
lukebronts commentedon Oct 8, 2019
Hi,
I am running into the same issue. We just upgraded one of our apps to .netcore 3. Connecting to sql works on my windows dev machine, but when we deploy to our staging environment (ECS cluster on AWS - linux machines) it stops working.
The error we get in our logs is: System.InvalidOperationException: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.
The connection string is: Application Name={appName};Server={host};User ID={id};Password={password};Database={dbname};Persist Security Info=false;Connection Lifetime=60
The machine has access to the sql box, if I role the code back to the .net core 2.2 version everything works fine. Its after upgrade to .netcore 3 it has stopped.
The code that fails is simply
using (SqlConnection connection = new SqlConnection(settings.ConnectionString))
{
connection.Open();
}
The sql box is an RDS instance provided by AWS. The Engine version is 13.00.2164.0.v1. I dont seem to be able to see what version of sql server it is under the hood, but it looks like its 2016 (https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_SQLServer.html)
The EC2 box inside our ECS cluster is Amazon Linux AMI 2018.03.p x86_64 ECS HVM GP2
Docker Images used:
mcr.microsoft.com/dotnet/core/aspnet:3.0
mcr.microsoft.com/dotnet/core/sdk:3.0
cheenamalhotra commentedon Oct 8, 2019
Hi @lukebronts
Could you tell us the version of Microsoft.Data.SqlClient driver in use?
Please try updating to latest Microsoft.Data.SqlClient version "1.0.19269.1" and confirm if the error occurs again.
Also please confirm SQL Server version from RDS cluster, by executing
SELECT @@VERSION.lukebronts commentedon Oct 8, 2019
Hi @cheenamalhotra
I have tried both 1.0.19269.1 and the current one in preview 1.1.0-preview1.19275.1. Both do not work.
The sql version is Microsoft SQL Server 2016 (RTM-CU2) (KB3182270) - 13.0.2164.0 (X64) Sep 9 2016 20:13:26 Copyright (c) Microsoft Corporation Standard Edition (64-bit) on Windows Server 2012 R2 Standard 6.3 (Build 9600: ) (Hypervisor)
lukebronts commentedon Oct 22, 2019
Hi @cheenamalhotra
Do you have an update on this issue? Have you managed to find anything?
Thanks
mgbee8 commentedon Oct 30, 2019
Having the same issue Sql Server Version is 2016, running in Docker with netcore 3 using mcr.microsoft.com/dotnet/core/runtime:3.0-buster-slim
using System.Data.SqlClient 4.7.0 and tried 4.8.0-preview1.19504.10, same issue
yukiwongky commentedon Oct 30, 2019
@mgbee8 does it work for you if you use netcore 2.2? Also, can you try to use the latest Microsoft.Data.SqlClient?
18 remaining items
albeserra commentedon Apr 2, 2020
Dear all, I get same error trying to connect to a SQL SERVER 2008. Code works like a charm in windows and mac (with dotnet for mac). But I get an error on the ubuntu docker container.
Do you have any advice? thanks
Connecting to SQL Server ... Microsoft.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: 0 - Success)
at Microsoft.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action
1 wrapCloseInAction) at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at Microsoft.Data.SqlClient.TdsParserStateObject.ThrowExceptionAndWarning(Boolean callerHasConnectionLock, Boolean asyncClose) at Microsoft.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject stateObj, UInt32 error) at Microsoft.Data.SqlClient.TdsParserStateObject.ReadSniSyncOverAsync() at Microsoft.Data.SqlClient.TdsParserStateObject.TryReadNetworkPacket() at Microsoft.Data.SqlClient.TdsParserStateObject.TryPrepareBuffer() at Microsoft.Data.SqlClient.TdsParserStateObject.TryReadByte(Byte& value) at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) at Microsoft.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) at Microsoft.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) at Microsoft.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover) at Microsoft.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) at Microsoft.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) at Microsoft.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling, String accessToken, DbConnectionPool pool, SqlAuthenticationProviderManager sqlAuthProviderManager) at Microsoft.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) at Microsoft.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) at Microsoft.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) at Microsoft.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)at Microsoft.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource
1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) at Microsoft.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions)at Microsoft.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource
1 retry, DbConnectionOptions userOptions) at Microsoft.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 retry)at Microsoft.Data.SqlClient.SqlConnection.Open()
at WebApplication4.Controllers.WeatherForecastController.Get() in /src/WebApplication4/Controllers/WeatherForecastController.cs:line 66
ClientConnectionId:c57a691e-9396-4b55-9983-ab20679e9a26
jean-lourenco commentedon Apr 2, 2020
I have the same "hanging sql server connection" problem with this setup:
Before applying the SP3 , the error was about failures around TLS handshake.
After SP3 was installed this error ceased, but now the connections just hangs foverer.
I've tried changing the base images, but all of the dotnet 3.1 images have the same problem.
Also I tried the SECLEVEL and MinTLSSupportedVersion scripts on the Docker imagem construction, no luck either.
This same app can connect normally on Windows, and the container can connect normally on SQL Server 2014 (SP3).
cheenamalhotra commentedon Apr 2, 2020
@jean-lourenco
Could you try removing the SECLEVEL scripts and let driver connect with TLS 1.2 if your server has all the updates?
jean-lourenco commentedon Apr 2, 2020
@cheenamalhotra I've tried that too, didn't work.
rdagumampan commentedon Apr 11, 2020
@albeserra have you managed to resolved this case? We also had this issue on service running on container.
May i what does this line means? What does it do? TIA
rdagumampan commentedon Apr 11, 2020
Hi all,
Updating the CA certificates in the base image of container have solve this for our case. See docker file below. I tried many options including @albeserra suggestions and I have remove many things and trimmed to this only command and it seems to what have resolved our case.
Background:
jean-lourenco commentedon Apr 14, 2020
After some days I tried this again and managed to get the container working with the @iarovyi sugestion. Idk what I was doing wrong previously, probably not building the container image correctly.
@rdagumampan It comments out the
ssl_conf = ssl_sectline of the open ssl config file.albeserra commentedon Apr 14, 2020
Hi, no I didn't solve it. We abandoned the idea to build a .NET image for a linux container :( how did you solve it?
kolesso-programist commentedon May 7, 2020
@sjc1832 did you solve this issue ? could you provide details please
kolesso-programist commentedon May 7, 2020
@voroninp did you solve this issue ? could you provide details please
voroninp commentedon May 7, 2020
@kolesso-programist Alas, I quit that company, so cannot add more details on whether issue was resolved or not.
emanuelmaha commentedon Jun 3, 2020
you made my day happier
cheenamalhotra commentedon Jun 10, 2020
Hi everyone, since #577 fixes the hang issue and will be released with Microsoft.Data.SqlClient v2.0.0, we will close the issue. This fix will also be backported to System.Data.SqlClient soon.
The recommended solution for anyone facing "End of Stream reached" exception in future is to verify target SQL Server supports TLS 1.2+ and server certificates are encrypted with SHA256+.
There are workarounds to switch back to lower TLS version if needed, as discussed above, but starting next release (v2.0), applications will also receive a warning as implemented in #591 if a lower insecure TLS version was negotiated with server, since these versions are not recommended for client applications. It includes raising warning for TLS v1.0 and TLS 1.1 protocols.
pandu-malik commentedon Oct 31, 2023
Thanks a lot man, you save alot of my 3 days of struggling