I have created a Dockerfile for my .NET program. The program runs fine on my desktop and on an Windows Server 2016 (Azure VM) without Docker. When I try to run it inside as a container (based on microsoft/windowsservercore), then I often get database errors when connecting to my Azure SQL instances.
I have two Azure SQL instance running (P1 and no load). When a connection can be established, then they are pretty fast, but the problem is that the connection often cannot be established. It looks like the network is very unstable. These are typical errors that are thrown at me:
System.Data.SqlClient.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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
The inner exception reports The network path was not found. At first I thought it might be my local machine, but it also has issues on the Windows Server 2016 (with containers) VM instance in Azure.
To pinpoint the problem I have created a test program that connects to my databases every 5 seconds (and runs SELECT COUNT(*) from sysobjects
). This program always succeeds to find the database.
It seems that my other program often fails during startup, but during initialization there are a lot of database calls. I suspect something is different with threading, connection pooling, ...
Anyone a clue?