I have a C# program which I want to connect to a simple Dockerized SQL Server database on Windows. The docker-compose.yml for the database looks like this:
version: "3.9"
services:
db:
image: "mcr.microsoft.com/mssql/server"
environment:
SA_PASSWORD: "*****"
ACCEPT_EULA: "Y"
Now I am trying to connect to it in C# like this:
SqlConnection connection = new SqlConnection(@"Server=db;Database=master;User=sa;Password=*****;");
connection.Open();
At connection.Open() it fails with this error:
System.Data.SqlClient.SqlException: [...]
System.ComponentModel.Win32Exception: The Network Path could not be found
It seems obvious to me that the problem is the connection string. However, I have searched and searched and wasn't able to figure out what the correct connection string in this case would be. Can someone please help me out?
EDIT:
I now also tried this connection string:
@"Server=localhost,1433;Database=master;User=sa;Password=*****;"
This result in the following, different error:
System.ComponentModel.Win32Exception: The Remote Host refused the network connection
docker-compose.ymlis literally the complete file, and I don't know anything about bridges and networks, which is why I'm asking what I need to do to get this to work.