"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: 0 - The
remote computer refused the network connection.)"
That is, it fails when trying to connect with 'localhost' as host, it is successfully connecting when "127.0.0.1" is specified as host.
The same happens when I tried to connect with SQL server management studio.
I could able to connect with 'localhost' to db with udl file also:
My docker engine is running in wsl, an ubuntu distro specifically. There is MySQL and different other servers already spun up which I can access with localhost.
Is there anything I need to specify in docker-compose to make this work? When checking documentation, there are no params aligned to it as I see.
Azure: A cloud computing platform and infrastructure for building, deploying and managing applications and services through a worldwide network of Microsoft-managed datacenters.ISV (Independent Software Vendors) and Startups: A Microsoft program that helps customers adopt Microsoft Cloud solutions and drive user adoption.
Hi @Vishnu Prasad-FT ,
We have not received a response from you. Did the reply could help you? If the response helped, do "Accept Answer". If it doesn't work, please let us know the progress. By doing so, it will benefit all community members who are having this similar issue. Your contribution is highly appreciated.
Best regards,
Seeya
Hi @Vishnu Prasad-FT ,
In order to benefit all community members who are having this similar issue, please choose an answer to accept or vote for the answer you think is useful to you. Your contribution is highly appreciated.
Best regards,
Seeya
Hi @Vishnu Prasad-FT ,
I've done a similar thing to you and am able to get this working for both localhost and 127.0.0.1.
$guid = New-Guid
$containerName = 'Sql2017-Local'
docker pull mcr.microsoft.com/mssql/server:2019-latest
docker run -p 51433:1433 -e "MSSQL_SA_PASSWORD=SecurePassword1!" -e "ACCEPT_EULA=Y" -e "MSSQL_PID=Developer" --label source="$containerName" -d --name "$containerName-$guid" -v sql2017volume:/var/opt/mssql mcr.microsoft.com/mssql/server:2017-latest
As you can see, I am able to connect (using SSMS) to both endpoints on the specified port.
Additionally, I was able to connect using the below code through PowerShell.
$sqlConn = New-Object System.Data.SqlClient.SqlConnection
$sqlConn.ConnectionString = "Server=localhost,51433;Integrated Security=false;Initial Catalog=master;User ID=sa;Password='SecurePassword1!'"
$sqlConn.Open()
$sqlConn
And you can see the connection is open:
And with 127.0.0.1, again you can see the connection working with PowerShell.
$sqlConn = New-Object System.Data.SqlClient.SqlConnection
$sqlConn.ConnectionString = "Server='127.0.0.1,51433';Integrated Security=false;Initial Catalog=master;User ID=sa;Password='SecurePassword1!'"
$sqlConn.Open()
$sqlConn
As was said in a previous answer, maybe check if you have a firewall blocking connections. Alternatively, try changing "Data Source" to "Server" and maybe try surrounding your password with quotes?
Interesting you would call that out - I've just checked and yes it looks like I'm using WLS2 backend (not WSL - I wonder if this makes a difference?). I'm also using Docker v20.10.22 & docker desktop 4.16.3 (96739) - maybe an update for docker might help?
Otherwise, could you try either redownloading the 2017 image, and/or also try the MCR/SQLServer:2019-latest? I wonder if the image could somehow be corrupted (I don't know that this can even happen - but something to try)?
If connections are working via 127.0.0.1 but not via localhost, can you check the SQL Errorlogs? There may be something more helpful in there?
Hi @Vishnu Prasad-FT ,
Please check if all the network protocols of SQL Server Configuration Manager are turned on. If they are, please go to properties again and check if the port number is 1433.
Also, go to your firewall and check if this port is blocked.
Best regards,
Seeya
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".