Mac: Cannot connect to SQL server through Docker

I have an application which uses LocalDB and runs fine on a Windows PC, however I am trying to run this through my mac…. I’m struggling with connecting the application to a mySQL server which sits on docker. I have been following the other guides such as (https://docs.microsoft.com/en-us/sql/linux/quickstart-install-connect-docker?view=sql-server-ver15&pivots=cs1-bash) related to this topic with no luck…

Here’s what I’ve done so far, through terminal:

  • sudo docker pull mcr.microsoft.com/mssql/server:2019-CU5-ubuntu-18.04

  • sudo docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=<MyPassword123!>"
    -p 1433:1433 –name sql_container
    -d mcr.microsoft.com/mssql/server:2019-CU5-ubuntu-18.04

  • Verified this is running by using sudo docker ps -a Verified container running

  • Also verified by using Kitematic, container seems to be running well

  • MySQL looks well set-up in System Preferences

Image of System Preferences

  • I am able to connect to the container through Azure Data Studio using IP address as server name, as shown below

Azure Data Studio enter image description here

  • Within the Application, this is is what the ConnectionStrings look like within the appsettings.json folder…appSettings.json
  • However, when I run the application and try and hit the container, through a GET request OR on Swagger, I am met with the following reply; "error": "Cannot connect to SQL Server Browser. Ensure SQL Server Browser has been started."
  • I have researched this and tried the solution of including the port number after the IP number as such Server=(19X.XXX.X.XX, 1433) but this also comes back with the error; "error": "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: 25 – Connection string is not valid)"

I’m not sure where to go from here… any help to get this working would be greatly appreciated!

Add Comment
1 Answer(s)

As trivial as it was, the correct syntax to make this work is Server=XXX.XXX.X.XX,1433

DO NOT INCLUDE PARENTHESES AND NO SPACE BETWEEN IP AND PORT

Answered on August 30, 2020.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.