0
votes

I am trying to connect to MSSQL via Visual Studio Code with installed mssql extension. I did pull and run SQL Server 2017 container image with Docker and I am trying to make a connection, although I do get an error:

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: 25 - Connection string is not valid) ---> System.Net.Sockets.SocketException (0x80004005): Undefined error: 0 at System.Data.SqlClient.SN

The container image is running - I did log on to MSSQL through terminal, but I can't with Visual Studio Code. Do I have to provide an instance as well? Where I can find it - cannot find it on docker inspect statement.

Did you guys have similar problem and maybe found a solution?

1
can you share your connection stringTheGameiswar
Please share the connection string and also how you ran the sql container, please share the complete commandTarun Lalwani
I run the sql container with the following comand docker run -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=<MyPass>' -p 1433:1433 --name sqlcontainer1 -d microsoft/mssql-server-linux For the connection I was trying both with localhost and with the internal IP of the host and still nothing Server=localhost; User Id=SA; Password=MyPass;Mateusz Dygas
When I run docker inspect I do get "NetworkMode": "default", "PortBindings": { "1433/tcp": [ { "HostIp": "", "HostPort": "1401" } ] }, Does this mean that I cannot connect to sql server outside of the container? Where I can check whether I can connect to container remotely?Mateusz Dygas
Update I did connect to the sql server via SQLPro for MSSql, although I did it through port 1401. Anyway I still cannot connect via VSC.Mateusz Dygas

1 Answers

1
votes

Okay I managed to solve the problem. I do connect to sql server container on 1401 port (localhost,1401 on VSC), but apparently when you start a container you need to change the password for sa. Rookie mistake :) Thanks for trying to help