I have a ASP.NET Core 2.2 project for which I turned on docker support. The project runs fine as long as it does not require database connection. For e.g Login. When I enter user credentials, I get the error as below.
An unhandled exception occurred while processing the request. 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
Unknown location 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.)
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, object providerInfo, bool redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, bool applyTransientFaultHandling) InvalidOperationException: An exception has been raised that is likely due to a transient failure. If you are connecting to a SQL Azure database consider using SqlAzureExecutionStrategy.
Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerExecutionStrategy+d__7.MoveNext()
Previously the error was different when TCP/IP was not enabled in my sql server configuration manager.(Do not remember error) I followed the steps mentioned in the link https://jack-vanlightly.com/blog/2017/9/24/how-to-connect-to-your-local-sql-server-from-inside-docker to solve that issue.
I have enabled TCP/IP and named pipes as well. Also I can connect using IP from SQL Management Studio.
Current connection string:
"ConnectionStrings": {
"DefaultConnection": "Server=xxx.xx.xx.x,1433;Database=TestDB;User ID=username;Password=pwd;Trusted_Connection=True;MultipleActiveResultSets=true"
},
Please let me know if I am missing any step. I want to connect to a local sql from my docker project