Kubernetes A network-related or instance-specific error occurred while establishing a connection to SQL Server

8/1/2018

I have docker that running on kubernetes, the site is able to browse from the browser. When performing request API, that requires a connection to the database. The database is hosted on SQL Azure NOT on another docker.

I got this error

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.

How to troubleshoot and fixed the issue?

-- Herman
azure-aks
azure-sql-server
docker
kubernetes
sql-server

1 Answer

8/7/2018

I have found the issue, The issue is dockerFile connectionString is still using the one in appsettings.json.

I have passed the environment like this

kubectl run identityapi --image xxxxxxxx.azurecr.io/panda/identity.api --port=80 --env="ASPNETCORE_ENVIRONMENT=Development" --env="ConnectionStrings__DefaultConnection=Server=xxxxxxxx.database.windows.net,1433;Initial Catalog=panda.identity;Persist Security Info=False;User ID=xxxxxxxx;Password=xxxxxxxx;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"

The environment for ConnectionStrings__DefaultConnection must use double underscore instead of dot (.)

-- Herman
Source: StackOverflow