Issues with SQL Connection from an IIS ASP.NET container

2

Background: I'm porting over applications to docker containers using the latest 4.8 ASP net container. They all use SQL Server connections.

App1: Framework 4.8, no issues at all. App2: Framework 4.6.2, can't establish a connection to the SQL Server at all.

Here's the connection string:

<add name="DefaultConnection" connectionString="Data Source=172.31.0.2; Initial Catalog=Integ_Catalog; User ID=MYUSER; Password=Pa55W0rd; MultipleActiveResultSets=True;Connect Timeout=120" providerName="System.Data.SqlClient" />

From within the container, I've ran Powershell to verify the connection string is 100% working. I've updated dapper to the latest version hoping that would help. Any ideas what to try?

Trace

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) ---> System.ComponentModel.Win32Exception (0x80004005): The network path was not found
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   at System.Data.SqlClient.SqlConnection.Open()

* Update *

When the app was within the same AWS VPC as the DB, the calls would fail. But when they are in a different VPC, it would work. This makes no sense, you'd think it would be the other way around. Networking on the DB, App/Host and within the VPC look fine.

asp.net
sql-server
docker
iis
containers
asked on Stack Overflow May 7, 2020 by Derrick M • edited May 9, 2020 by Derrick M

2 Answers

0

Solution was to move app over to an outside VPC, why? The world may never know :)

answered on Stack Overflow May 11, 2020 by Derrick M
0

You need to add IIS_USR in SQL Server and need to give permission to access the Database

answered on Stack Overflow May 15, 2020 by Sanjay Gangurde

User contributions licensed under CC BY-SA 3.0