ASP.NET Core MacOS Connection string

2

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.

c#
mysql
entity-framework
asp.net-core
entity-framework-core
asked on Stack Overflow Dec 19, 2018 by Markiian Benovskyi • edited Dec 19, 2018 by Roman Marusyk

1 Answer

3

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
answered on Stack Overflow Dec 19, 2018 by Roman Marusyk

User contributions licensed under CC BY-SA 3.0