0

I have been trying to use Entity Framework to connect to a MySQL database, database first, but I can´t get any connection to the database. When searching google and mysql.com, I only get guides thats telling me to use code first or model first.

What I want is what I always do: Add new Entity Data Model, write the credentials to the database and then, everything works just fine and I can write my LINQ queries as I am used to.

I am using Windows 8, VS 2013 ultimate, Environment.Version is 4.0.30319.36366.

How can I connect to MySQL with EF database first?

enter image description here

Martin Nilsson
  • 459
  • 1
  • 5
  • 15
  • you need to post your code in question instead of image link. Thanks – Zaheer Ul Hassan Apr 07 '17 at 07:19
  • when exactly you are getting this error ? Similar type question is already available, please check if it helps http://stackoverflow.com/questions/18060667/why-am-i-getting-cannot-connect-to-server-a-network-related-or-instance-speci – Naveen K N Apr 07 '17 at 07:26
  • The error says that the SQL Server is not accessible. EF code generator is not able to connect to the database server. Did you verify that if you are able to the database server from Sql Management Studio from the machine where your code is ? – Chetan Apr 07 '17 at 07:30
  • There is no code to show, I am adding a new Item to my project: ADO.NET Entity Data Model -> EF Designer from database -> clicking Next button -> New Connection -> Here Im filling in Server name, User name and Password. Against a "normal" database, this is all I need to do. – Martin Nilsson Apr 07 '17 at 07:42
  • Yes, I can acces the database by doing the following: download some nuget packages (I have downloaded a lot of them now so I don´t know which is the correct), and write 3 lines of code 1. "var conn = new MySqlConnection();", 2. conn.Connectionstring = ".....", 3. conn.Open(). That works which means I have the correct credentials. – Martin Nilsson Apr 07 '17 at 07:45
  • the datasource needs to be changed to mysql as now you are trying to connect to SQL Server, refer @Learning answer. – Anil Apr 07 '17 at 08:34

1 Answers1

1

enter image description hereThat's a common error when you first load the EF Designer. I don't know if its the same in VS 2013 but In VS 2015 You can create a new connection and select MySQL, but MySQL For Visual Studio should be properly installed.

Learning
  • 163
  • 1
  • 11
  • Thank your for reply, however, this is something I have already tried. The MySQL Database option does not appear in my Visual Studio. Any suggestions? – Martin Nilsson Apr 07 '17 at 08:44
  • Try to reinstall the MySQL For Visual Studio Also please read this http://stackoverflow.com/questions/16879451/mysql-data-source-not-appearing-in-visual-studio It might help – Learning Apr 07 '17 at 08:48