I am trying to connect to a Docker image SQL Server database through another containerized application (microservice) built with .NET Core 3.1 but I get the following error thrown by Docker:
fail: Microsoft.EntityFrameworkCore.Database.Connection[20004]
An error occurred using the connection to database 'ProductDb' on server 'localhost,1433'.
fail: Microsoft.EntityFrameworkCore.Query[10100]
An exception occurred while iterating over the results of a query for context type 'Infrastructure.ProductContext'.
Microsoft.Data.SqlClient.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: TCP Provider, error: 40 - Could not open a connection to SQL Server)
The connection string I am using is:
"ProductDb": "Server=localhost,1433;Database=ProductDb;User Id=sa;Password=********;"
I need to mention that this same application works fine when it's hosted on a IIS server.
localhost,1433with.,1433? And is the 1433 even necessary as that is SQL Server's default port.