I cannot connect to SQL Server through Visual Studio Code on Mac


I'm a new user to Mac OS and I'm using Visual Studio Code as a text editor. I want to create my very first SQL.

I've been following step by step on this sites : https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-develop-use-vscode

Also i have also installed the OpenSSL following the step by steps on this sites : http://mac-dev-env.patrickbougie.com/openssl/

The problem is when I try to make an SQL connection at the very first time, it gives me an error like this :

mssql: Failed to connect: System.Data.SqlClient.SqlException (0x80131904): 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: 35 - An internal exception was caught) ---> System.AggregateException: One or more errors occurred. (Connection refused [::1]:1433) ---> Sys RetryClose Error

How can I fix this problem and create my first new SQL? Thanks

asked on Stack Overflow Sep 20, 2017 by fonmagnus • edited Sep 20, 2017 by a_horse_with_no_name

2 Answers


Are you sure your docker container is running? You can check it with "docker ps" in the terminal. You also have to make sure that you map to port 1433 when creating the container.

Hope it helps.


I was able to run SQL server on MAC using Docker by running it along with the Azure Data Studio. Per your post, i am not sure if you have installed docker or is your docker running in the background while you try to connect to the server(if docker is already installed).

In order to connect to a server, you need to go to preferences of your Docker settings and increase the Memory allocation from the default of 2GB to minimum 4GB (as SQL server needs min 3.25GB space). Save and restart the docker.

Once restarted, all you need to do is pull the docker image of the sql server and download it. this can be done by below commands on your terminal . FYI, I am using bash commands below:

Command 1:

sudo docker pull mcr.microsoft.com/mssql/server:2017-latest

This will pull the latest vesion docker image and download. Once done, you need to set your SQL authentication on the server for your database. Follow below commands:

Command 2:

    sudo docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=<SetYourPasswordHere>' \
   -p 1433:1433 --name sql1 \
   -d mcr.microsoft.com/mssql/server:2017-latest

This sets your password and uses the port 1433 for SQL server (which is the default port). To confirm if the image has been created and the SQL server is running on docker, execute the below command to check log(s).

Command 3:

docker ps

To check all instances in your history of dockers( i.e. if you already had dockers installed before you are attempting this SQL connection/execution), run the below command and it will give you all the logs of all instances you have created

Command 4:

docker ps -a 


docker ps -all

Once, you have completed above steps and see that the docker has created SQL instance, you need to go to Azure Data Studio and set the below credentials to access the server that you just created above using Docker.

Server: localhost
Authentication Type: SQL Authentication
Username: sa
Password: <Check Command 2 to see what you entered in the password where it says SetYourPasswordHere>

Hope this helps in your tryst with running SQL server on your MAC. All the Best!

answered on Stack Overflow Sep 25, 2019 by Anchit

User contributions licensed under CC BY-SA 3.0