C
C#4mo ago
Tiltyboi

✅ Cannot connect to mysql docker container db from AspNet Core App

A AspNet Core App using EF-Core cannot connect to local db container running mysql. I have made sure it forwards the correct port (default 3306). ASet my connection string in my app to:
"ConnectionStrings": {
"SqlConnection": "Server=172.17.0.2;Database=test-db;User Id=root;Password=my-secret-pw;"
}
"ConnectionStrings": {
"SqlConnection": "Server=172.17.0.2;Database=test-db;User Id=root;Password=my-secret-pw;"
}
So why doesnt it work? I alsot ried setting server to localhost and 127.0.0.1 ....
13 Replies
jcotton42
jcotton424mo ago
can you show the docker command or compose that started the mysql container? also, is that asp.net app itself running in docker? (actually, answer question #2 first)
Tiltyboi
TiltyboiOP4mo ago
No my app is runnig on host machine while my mysql server is running on a docker container on my host. i tried creating a standalone app with the same connection string and connecting, it worked after creating the database manually in the docker container. But then trying from Update Database doesnt work and gives this error:
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)
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)
@beware of the leopard
jcotton42
jcotton424mo ago
uh, that error seems to be for MS SQL Server but your initial message said MySQL @Tiltyboi
Tiltyboi
TiltyboiOP4mo ago
Is that not the same `?
jcotton42
jcotton424mo ago
no
Tiltyboi
TiltyboiOP4mo ago
Sorry i dont know .NET very well
jcotton42
jcotton424mo ago
so which database are you intending to use?
Tiltyboi
TiltyboiOP4mo ago
Well i want to use mysql becuase i have experience in it but my image is mysql:latest
jcotton42
jcotton424mo ago
Database Providers - EF Core
Information about specific supported Entity Framework Core providers and about providers in general
Tiltyboi
TiltyboiOP4mo ago
Ah that worked! Thanks so much! @beware of the leopard :prayge: Have a good day/evening
jcotton42
jcotton424mo ago
$close
MODiX
MODiX4mo ago
If you have no further questions, please use /close to mark the forum thread as answered
jcotton42
jcotton424mo ago
np
Want results from more Discord servers?
Add your server