1

I recently set up a docker container to host SQL server 2017 on my Mac. I am using Azure data studio as the GUI for the connection. Below you will find a link to see exactly how I setup this connection. Upon establishing the connection everything works great. I can even disconnect and reconnect to the locally hosted database.

When I restart my computer I cannot seem to reconnect to the local host. I open terminal and see that I my sql server studio database is running. I open Azure data studio and it will not automatically connect. I go into Azure connection and I specify local host, username "sa", the password and the port number. Azure will not connect to the docker container and locally hosted database.

I receive the following 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)

If someone could help me out I would really appreciate it. I do not have to rebuild what I have currently done for school each time I restart my machine. Thank you.

Setup link: https://adamwilbert.com/blog/2018/3/26/get-started-with-sql-server-on-macos-complete-with-a-native-gui

1 Answers1

1

You'll have to re-start the docker container before connecting to the server using Azure Data Studio.
Open a terminal window and execute the command to start the SQL server on docker

sudo docker run -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=YourStrong!Passw0rd' -p 1401:1433 --name sqlserver1 -d microsoft/mssql-server-linux:2017-latest

Next go to Azure Data Studio and connect to the database.

Marc0
  • 181
  • 7
  • I am still receiving the same error message. If we do get this to work is there anyway to have the service automatically start and connect upon opening azure? My previous container was running that I was trying to connect to. 25781a0b9d85 microsoft/mssql-server-linux:2017-latest "/opt/mssql/bin/sqls…" 26 hours ago Exited (255) 25 hours ago 0.0.0.0:1433->1433/tcp SQL_dbo – Crucial Dynamics Jan 23 '19 at 17:49
  • Well, I think I solved my own problem. I ran the terminal command docker ps -a and saw that my sql server instance was running. I downloaded and kitematic which showed the sql container. I restarted the container in Kitematic which did appear to be running. Without making any changes to the login creds I was able to once again connect to the locally hosted database. Is there something that I can do to ensure that the service is always up? – Crucial Dynamics Jan 23 '19 at 18:03
  • From what I remember you need to start the container every time unless you configure the policy for the container. I have never done it but here's a reference to configure this link https://docs.docker.com/config/containers/start-containers-automatically/ – Marc0 Jan 23 '19 at 18:10
  • Thank you Marc0. I sincerely appreciate your help. – Crucial Dynamics Jan 23 '19 at 18:13
  • I did try the automatic restart command but it did not work successfully. If I can get this to work I will post the answer. – Crucial Dynamics Jan 24 '19 at 16:10
  • Have you tried updating the container policy like so? `docker update --restart always `. On this link https://blog.codeship.com/ensuring-containers-are-always-running-with-dockers-restart-policy/ and here https://stackoverflow.com/questions/29603504/how-to-restart-an-existing-docker-container-in-restart-always-mode there are some more info on how to do it – Marc0 Jan 24 '19 at 20:21