I have created a MySQL database in MySQL Workbench but am unable to use in C#

176 views Asked by At

Hi I am new in C# programming and MySQL but I want to learn it. I have created a database in a MySQL workbench, in which I have created a table and inserted some data.

Now I want to use this database in my C# desktop application. But how do I connect C# with that database? I do not know where the database is located.

If I know the location then I can enter its address in connection string in C#, so my questions are

  1. After creating a database in MySQL workbench then where is the file saved?
  2. Should I place that database file with my .exe file ?
1

There are 1 answers

0
ViVi On
  1. Install MySql connector for .net/ODBC
  2. Install MySql for visual studio
  3. Import MySql.Web, MySql.Data and MySql.Data.Entity.EF6 dlls into your project first.
  4. Now create a Entity framework data model from your database by right clicking any folder -> new item -> Data -> ADO.net entity data model
  5. Click Generate from database -> Next
  6. Click on New Connection -> Change ->
  7. Select MySql Database as datasource
  8. Give your MySql server credentials and select database to generate the data model from database
  9. Now you can create the instance of the entities class and access data from tables like dbEntitiesInstance.TableName.(Make use of LINQ queries too).