Encrypt=false not working
See original GitHub issueDescribe the bug
I am trying to connect to SQL Server using Encrypt=False but I cannot get it to work. SQL Server is 2016 placed on Windows Server and configured to not require encryption.
Connection string used:
Data Source=hostname\\aaa;Initial Catalog=SampleDB;User ID=sa;Password=Sample123;Pooling=True;Min Pool Size=3;Max Pool Size=10;Connect Timeout=5;Trust Server Certificate=False;Encrypt=false;
Exception message:
Unhandled exception. Microsoft.Data.SqlClient.SqlException (0x80131904): A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: SSL Provider, error: 31 - Encryption(ssl/tls) handshake failed)
---> System.IO.IOException: Received an unexpected EOF or 0 bytes from the transport stream.
Further technical details
Microsoft.Data.SqlClient version: 4.1.0 .NET target: 6.0 SQL Server version: (e.g. SQL Server 2016) Operating system: Alpine Linux .NET 6 Runtime container
Additional context This does not happen when the client is a Windows machine. .NET 3.1 based service works without any issue
Issue Analytics
- State:
- Created a year ago
- Comments:21 (11 by maintainers)
Top Results From Across the Web
TLS when connecting to SQL Server using "encrypt=false"
Encrypt=false indicates the client does not require encryption. TLS will still used when possible, encrypting login credentials at a minimum ...
Read more >Sqlconnection still requires ssl but "encrypt=false"
I've tried to force encrypt=false in the connect string to disable any SSL option, but this does not solve the problem.
Read more >Connecting with encryption - JDBC Driver for SQL Server
When the encrypt property is set to true and the trustServerCertificate property is set to false, the Microsoft JDBC Driver for SQL Server ......
Read more >Problems upgrading MSSQL's JDBC to 11.2 and how to set ...
1. Problems upgrading MSSQL's JDBC to 11.2 and how to set properly encrypt=false in the JDBC URL. BREAKING CHANGE TLS encryption is enabled...
Read more >Connection Failures with Microsoft.Data.SqlClient 4 and later
Luckily the fix is pretty simple - once you know what the problem is - as you can just specify Encrypt=False on the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
In my case, I was running
mssql/server:2019-laterin Docker on an Azure Pipelines build agent.All connections failed with
A connection was successfully established with the server, but then an error occurred during the pre-login handshake..Encrypt=Falsein the connection string did not help.From SQL logs, it turned out the problem was with the mounted volumes:
ERROR: BootstrapSystemDataDirectories. This is a known issue: https://github.com/microsoft/mssql-docker/issues/602#issuecomment-629193915By not mounting Docker volumes, I could connect. So the original error message threw me off in the wrong direction, debugging SSL and TLS1.2.
Maybe this helps some others googling this.
I assumed this wasn’t possible but I thought I should check and see why. So i looked at the spec and interestingly it says:
So in theory if the server allows no encryption and the client allows no encryption then it is possible to skip the login encryption. However looking at the code for this library I found that:
https://github.com/dotnet/SqlClient/blob/38dfaaa8167024e8e00632569f1c2e3db5f47ef1/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs#L900-L905
So even if the client requests no encryption and the server would allow it we force login to be encrypted to protect the credentials being used. I think this is a good idea and the uses cases for totally disabling encryption aren’t good. Is there compelling reason that you can’t simply change the container security?