ASP.NET Core MacOS Connection string

asp.net-core c# entity-framework entity-framework-core mysql

Question

I have issues establishing connection to my mysql server database on MacOS using Entity Framework Core for ASP.NET Core 2.0 project.

I am following this tutorial: https://blog.jetbrains.com/dotnet/2017/08/09/running-entity-framework-core-commands-rider/

My database is started as a default mysql server service on my MacBook running on localhost:3306 and has a User and Password for login. I can connect to the database from DataGrip and Terminal.

When I am running this command to establish connection and create DBContext:

dotnet ef dbcontext scaffold "Server=(mysql)\localhost;Database=edums_development;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -c EdumsDataContext

I am having an error:

System.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: 25 - Connection string is not valid) ---> System.Net.Sockets.SocketException (0x80004005): Undefined error: 0

Obviously meaning that my connection string is incorrect.

I don't know what exactly is incorrect and how should I include username and password to make it connected successfully.

1
2
12/19/2018 11:53:21 PM

Accepted Answer

You are using wrong database driver Microsoft.EntityFrameworkCore.SqlServer, this one is for MS SQL Server, what actually says the error

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.

Try to use MySql.Data.EntityFrameworkCore instead

dotnet ef dbcontext scaffold "Server=(mysql)\localhost;Database=edums_development;Trusted_Connection=True;" MySql.Data.EntityFrameworkCore -c EdumsDataContext
3
12/19/2018 11:49:38 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow