I have a ASP.NET Core v3 Web API service. It runs and connects just fine to a normal Windows hosted SQL Server instance. But when I try to connect it to a Docker Linux hosted SQL Server Instance it fails.
Here are some details:
- Both containers are running on my Windows 10 Development Machine
- The Web API Service container is Linux based and works fine by itself
- The Linux SQL Server container works fine by itself
- I can connect and run queries via SSMS without issues.
- Both containers are one the same default Bridge network.
- I ran
docker network inspect bridge -f "{{json .Containers }}"and it listed both containers.
- I ran
Here is my database connection string:
"Server=localhost;Database=MyDatabase;User Id=MySqlUser;Password=MyPassword"
I also tried making an entry in my hosts file of localsql set to 127.0.0.0. Both localhost and localsql work fine to connect to the docker database using SSMS.
This is the actual error message:
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: 40 - Could not open a connection to SQL Server)
When I try using localsql from my hosts file, it has an inner exception with this message "Name or service not known"