dbcli / mssql-cli

A command-line client for SQL Server with auto-completion and syntax highlighting
BSD 3-Clause "New" or "Revised" License
1.36k stars 190 forks source link

WSL Ubuntu 20.04: TCP Provider Error: 40 Cannot establish connection. #510

Open gsmith077 opened 3 years ago

gsmith077 commented 3 years ago

I'm currently hunting down an error with mssql-cli on WSL2 running Ubuntu 20.04 where I am unable to connect to an external (Azure hosted) database. I do have Docker Desktop installed and am using the WSL2 integrations.

Attempts to connect end up with the following error, after a few minutes of it's not responding:

Error message: 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: 40 - Could not open a connection to SQL Server)

Command to start connection is in the form below: mssql-cli -S "Server.database.widnows.net,1433" -U Username -P password

I'm also getting the same error inside a C# project running in WSL, which is what led me to testing connection with mssql-cli.

hheexx commented 3 years ago

Same situation. From yesterday I can't start my dotnet project in WSL2 on Windows 11. but ping and sqlcmd work normaly

ivanlysakov commented 2 years ago

Same situation. I can't start my dotnet project in WSL2 on Windows 10. but ping and sqlcmd work normaly

ivanlysakov commented 2 years ago

Same situation. From yesterday I can't start my dotnet project in WSL2 on Windows 11. but ping and sqlcmd work normaly

wsl --update resolve this issue for me

hheexx commented 2 years ago

Not for me. No updates are available. Kernel version: 5.10.60.1

I fixed the problem with replacing hostneame of sql server in connection string with ip address. So it looks like it may be DNS resolving problem that only happens from dotnet.

ivanlysakov commented 2 years ago

Yeah, man! The issue in DNS resolving! By IP all works correctly. Thanks

chrisg123 commented 2 years ago

I faced the same issue. This solution worked for me.

Create a file openssl_tls1.cnf and put it anywhere with the following:

openssl_conf = default_conf

[ default_conf ]
ssl_conf = ssl_sect

[ssl_sect]
system_default = system_default_sect

[system_default_sect]
MinProtocol = TLSv1
CipherString = DEFAULT:@SECLEVEL=1

Then try to connect with the following command:

OPENSSL_CONF=openssl_tls1.cnf mssql-cli -S <SERVER> -U <USER> -P <PASSWORD>