0

My DB connection string uses this: Data Source=.\\sqlexpress; to point to the DB, this works when running the project diectly but not when running it inside docker locally using docker-desktop.

I tried using Data Source=localhost,1433; and mapping the port 1433:1433 in compose.yaml, but it didn't help, also I was looking in TCPView, didn't see SQL listening to 1433 or any other port.

Has anyone ever managed to connect to the localhost sqlexpress from inside docker container running also on localost?

3
  • 1
    Docker containers are essentially their own little Linux VMs, so from a networking point of view localhost, 127.0.0.1 and ::1 all reference the container itself. If you need to access services exposed or installed on the host, have you tried the special host.docker.internal name? Commented Mar 15, 2024 at 12:50
  • From inside of a Docker container, how do I connect to the localhost of the machine? discusses this at length; application in a container, database not in a container but on the same host (so two separate meanings of localhost). Does one of the techniques there help you? Commented Mar 15, 2024 at 13:40
  • I'm getting: A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 0 - Success) when using Data Source=host.docker.internal,1433 in my connection string Commented Mar 16, 2024 at 9:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.