Reputation: 51
I need help in writing a connection string to connect to a SQL Server database which is running in a docker container.
It's a .NET app that needs to be connected, but initially I want to test the connections with the database I have on SQL Server on docker.
IDE being used is Riders, OS is Mac OS.
Upvotes: 3
Views: 8521
Reputation: 664
If your .NET app is running into docker in the same solution, you have to use the name of sql server container.
docker-compose.yml
sqlserver:
image: 'microsoft/mssql-server-linux:2017-latest'
container_name: sqlserver
volumes:
- 'mssql-server-linux-data:/var/opt/mssql/data'
environment:
- ACCEPT_EULA='Y'
- SA_PASSWORD=xxxxxxxx
ports:
- '1433:1433'
Your connection string will be :
"ConnectionString": "Server=sqlserver;Database=xxxx;User Id=xx;Password=xxx;"
Otherwise, use in Server parameter the IP address for the computer hosting the container.
Upvotes: 6