Cannot connect my application to sql server on docker.
I tried to dockerise my asp.net application, but I get an error while applying migrations if I try to run locally. When I try doing it I have API turned off and SQL server turned on.
Docker-Compose
Dockerfile for API
Dockerfile for SQL
My connection sting is:
"Server=docker_sqlserver, 1433; Database=FitnessApp; User Id=sa; Password=myPassword1!; TrustServerCertificate=True;"
The are 2 exceptions
Inner Exception 1:
SqlException: 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: 0 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.)
Inner Exception 2:
Win32Exception: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
5 Replies
Dont the ports appear when you expose a container in docker desktop?
I see then on pc this is screen from laptop but they are viable in dockerfile I pasted
Can you access the db through dbms?
the ports would appear for published ports, but that shouldn't be done unless you want the db to be accessible outside the container network
yes, I found out that i have to use
Server=docker_sqlserver, 1433; inside container
Server=localhost, 1433; when i run locally