Connection string for sqlserver in Docker container

I am using Visual Studio 2017 for mac with dotnet Core and EF Core. After setting up the mssql image in the Docker container, I tried to add a connection string, but reset the connection error. I tried to use various parameters such as ip address, container name, host name, etc. As the server name, but none of them worked.

"Default": "Server=172.17.0.2; Database=ERPDb; User=sa; Password =******;" 

with container name

  "Default": "Server=ecstatic_hermann; Database=ERPDb; User=sa; Password=******;" 

with hostname:

  "Default": "Server=f45840a59623; Database=ERPDb; User=sa; Password=******;" 

When connecting through localhost in the terminal, its successful connection

 $ mssql -s localhost -p Technocrat123 Connecting to localhost...done sql-cli version 0.6.2 Enter ".help" for usage hints. 

But when the application starts, the connection fails.

Appreciate any help. Thanks in advance.

When using localhost error

 Login failed for user ''. Reason: An attempt to login using SQL authentication failed. Server is configured for Integrated authentication only. 
+10
docker connection-string macos
source share
3 answers

I just wrote a blog post about this. Take a look at richminchuk.io . Otherwise:

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

then,

 private static string _connStr = @" Server=127.0.0.1,1401; Database=Master; User Id=SA; Password=YourSTRONG!Passw0rd "; 
+8
source share

Most likely, your server name is localhost and port 1401 (which is used by default to configure the Docker container). Therefore, you will need the following connection string:

 "Default": "Server=localhost,1401; Database=ERPDb; User=sa; Password =******;" 
+5
source share

I had this problem today, and I solved it using a separate network (instead of using the default bridge network).

  1. docker network create test_network

  2. docker container run -p 1433:1433 -d --name mssql -v mssql_data: /var/opt/mssql -e SA_PASSWORD=********** -e ACCEPT_EULA=Y --network=test_network microsoft/mssql-server-linux

  3. docker container run -p 5000:80 --rm -e ASPNETCORE_ENVIRONMENT=Development --name aspnetcore --network=test_network aspnetcore-image

I also have a connection string like this:

 Server=mssql;Database=master;User=sa;Password=**********; 

As for the previous answers regarding the connection string with IP address, this is not a good approach, since this address can be dynamically changed, it is better to use container names as host names.

0
source share

All Articles