0

I have a .netframework 4.7.2 application with the azure database. I have created a docker windows container for this application. When I launch this application in the Docker container on my local machine, it gives an error:

[Win32Exception (0x80004005): The network path was not found]

[SqlException (0x80131904): 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)]

ConnectionString:
connectionString="Data Source=tcp:servername.database.windows.net,1433;Database=databasename;User ID=testuser;Password=testpassword;Trusted_Connection=False;MultipleActiveResultSets=True;Encrypt=True" providerName="System.Data.SqlClient"

Docker File:

FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8-windowsservercore-ltsc2019

ARG source

WORKDIR /inetpub/wwwroot

COPY ./bin/Release/Publish/ .

My IP Address is already added in the azure database and when I connect through the SQL management studio from the local machine it works without any issue. Also, It works fine with visual studio.

I believe my docker has internet access. When I ping google.com inside the docker container, it returns the result ping google

C:\inetpub\wwwroot>ping google.com

Pinging google.com [172.217.166.14] with 32 bytes of data:

Reply from 172.217.166.14: bytes=32 time=19ms TTL=118

Reply from 172.217.166.14: bytes=32 time=19ms TTL=118

Reply from 172.217.166.14: bytes=32 time=19ms TTL=118

Reply from 172.217.166.14: bytes=32 time=19ms TTL=118

Ping statistics for 172.217.166.14:

Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

Approximate round trip times in milli-seconds:

Minimum = 19ms, Maximum = 19ms, Average = 19ms

C:\inetpub\wwwroot>

Can someone guide me on how can I connect my application to the Azure database inside the docker container?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Anuj
  • 1
  • 1
  • I don't think the error message is coming from a piece of code that uses that connection string. `provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server` does not correlate with use of the TCP driver (not Named Pipes) in `Data Source=tcp:anyServerNameOrIpAddress;` – AlwaysLearning Mar 11 '22 at 21:57
  • Aside... to make use of Azure SQL instances on `database.windows.net`, in particular Azure-based authentication mechanisms, you'll probably want to switch from the legacy `System.Data.SqlClient` namespace and classes to the modern and better-supported `Microsoft.Data.SqlClient` namespace and classes. – AlwaysLearning Mar 11 '22 at 22:09
  • I checked the stack trace, the error occured at the following line: WebSecurity.InitializeDatabaseConnection("connectionstringName", "Databasename", "Id", "Name", autoCreateTables: false); I will try with "Microsoft.Data.SqlClient" and will update you, but on my local machine (visual studio), the code is working with "System.Data.SqlClient" – Anuj Mar 12 '22 at 07:33
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Mar 12 '22 at 10:19

0 Answers0