title: How do I access a MySQL database with Entity Framework
body: <p><strong>Background:</strong> I have already create a ASP.net MVC 4 app and a mysql database. I used code-first to generate the databases. The Web App is going to be used as the UI for interacting with the data. However the data is created in a separate C# program. Which gets test data from a serial device.</p>
  
  <p><strong>Problem:</strong>
  I can't figure out how to connect to the database with entity framework in my c# application. </p>
  
  <p>I have already create a new model for the C# app to use. I have read that using shared .DLL isn't the best idea.</p>
  
  <p>this is what I have so far.</p>
  
  <pre><code>    private ReportDBContext db = new ReportDBContext();
  
      private void saveReport()
      {
          string connStr = "server=RnD-Chopper;user=CWXDAQ;database=ReportDB;port=3306;password=QADXWC;";
          MySqlConnection conn = new MySqlConnection(connStr);
          try
          {
  
              db.Reports.Add();
  
              // Perform database operations
          }
          catch (Exception ex)
          {
              Console.WriteLine(ex.ToString());
          }
          conn.Close();
          Console.WriteLine("Done.");
  
  
  
  
          unlockGUI();
      }
  </code></pre>
  
  <p>report model</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel.DataAnnotations;
  using System.ComponentModel.DataAnnotations.Schema;
  using System.Data.Entity;
  using System.Data.Entity.Infrastructure;
  using MySql.Data.Entity;
  using MySql.Data.MySqlClient;
  using System.Linq;
  using System.Web;
  
  namespace CXW__DAQ___Record.Models
  {
      public class Report
      {
          [Display(Name = "Test ID #")]
          public int ID { get; set; }
  
          [Required(ErrorMessage = "Test Name is Required")]
          [Display(Name = "Test Name")]
          public string Name { get; set; }
  
          [Display(Name = "Date Tested")]
          public DateTime TestDate { get; set; }
  
          [Display(Name="Test Done For")]
          public string TestFor { get; set; }
  
          public string Comment { get; set; }
  
          public enum enumForceUnits { lbs };
          public enum enumTimeUnits { mS };
  
          [Required(ErrorMessage = "Unit of Force (ForceUnit) is required")]
          public enumForceUnits forceUnit;
  
          [Required(ErrorMessage = "Unit of Time (TimeUnit) is required")]
          public enumTimeUnits timeUnit;
  
          public virtual ICollection&lt;Reading&gt; Readings { get; set; }
  
      }
  
  
      public class Reading
      {
          public int ID { get; set; }
  
          public virtual Report Report { get; set; }
  
          public long Time { get; set; }
          public double Force { get; set; }
      }
  
  
      public class ReportDBContext : DbContext
      {
          public DbSet&lt;Report&gt; Reports { get; set; }
          public DbSet&lt;Reading&gt; Readings { get; set; }
      }
  }
  </code></pre>