question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

  • I have tested connections to this database with the old sqlcmd utility inside WSL, and that works correctly.
  • I can connect to the database using the Azure Data Studio on Windows.
  • I have installed mssql-cli via pip to windows directly, and that works correctly.
  • There does not seem to be a version of mssql-cli available in the microsoft repo for 20.04.
    • Attempting to apt install mssql-cli from the 18.04 source causes multiple package version misalignments, so that’s no viable.
  • Pip installed mssql-cli will not connect.

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.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:9
  • Comments:6

github_iconTop GitHub Comments

1reaction
hheexxcommented, Nov 15, 2021

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

0reactions
chrisg123commented, Mar 15, 2022

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>
Read more comments on GitHub >

github_iconTop Results From Across the Web

error: 40 - Could not open a connection to SQL Server
My window firewall is failed to connect. What to do to make it enable. ... You may check whether TCP/Named pipes setting is...
Read more >
Error: 40 - could not open a connection to sql server
In this tutorial, we will learn how to resolve the "provider: named pipes provider, error: 40 - could not open a connection to...
Read more >
Error: TCP Provider: Error code 0x2746. During the Sql setup ...
This is likely a problem with openssl vs. sql-server protocol/version. Check your openssl version. Run the following command on your terminal ...
Read more >
WSL - Ubuntu
Ubuntu on WSL. Install a complete Ubuntu terminal environment in minutes on Windows with Windows Subsystem for Linux (WSL). Access the Linux terminal...
Read more >
How to Fix the SSH "Connection Refused" Error - Kinsta
Are you experiecing the "Connection refused" error when connecting via SSH? ... You'll be back to running commands in no time flat.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found