I'm building a dotnet app using Rider and Docker under macOS. For the database, I use sqledge docker image. If I start the service and send a request, I receive a successful response. When I containerize the dotnet app, I receive the following error:
An error occurred using the connection to database 'FundraiserAPI' on server 'localhost'.
fail: Microsoft.EntityFrameworkCore.Query[10100]
An exception occurred while iterating over the results of a query for context type 'Raiserflow.CampaignOrgAPI.DbContext.FundraiserDbContext'.
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: Could not open a connection to SQL Server)
It's a common error that says that my dockerized service doesn't have access to the SQL container.
One of the ways to fix the error is to Enable TCP/IP port
As macOS doesn't support SQL Server Configuration Manager, do you know any other alternatives to enable the TCP/IP port of a SQL server in a docker container?
Attaching a screenshot of my 2 containers and the ports they're running.
And my connection string:
"DefaultConnection": "Server=localhost;Database=FundraiserAPI;Initial Catalog=FundraiserAPI;User=sa;Password=123123;MultipleActiveResultSets=True;"
Or if you have any other alternative solution, that would be great!