title: Entity Framework Core Error: An error occurred using the connection to database '' on server 'localhost'
body: <p>I have made an <code>ASP.NET Core 3.1</code> Web-based application and want to use MySQL as the database.</p>
  
  <p>I have been following along with some YouTube tutorials on creating <code>MySQL database</code> with <code>ASP.NET Core 3.1</code> <em>[code first approach]</em> including a tutorial from this site:</p>
  
  <p><a href="https://docs.microsoft.com/en-us/aspnet/core/data/ef-rp/intro?view=aspnetcore-3.1&amp;tabs=visual-studio" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/aspnet/core/data/ef-rp/intro?view=aspnetcore-3.1&amp;tabs=visual-studio</a></p>
  
  <p>I have created a <code>DataModel Class</code>, added a service to <code>UseMySQL</code> to the Startup.cs Class and created an <code>AppDBContext Class</code> that implements <code>DbContext Class</code>.</p>
  
  <p>When I run this command in the <strong>Package Manager Console</strong>: <code>Add-Migration InitialDatabase</code> the application is creating a migration successfully.</p>
  
  <p>When I run <code>update-database</code> it is throwing this exception:</p>
  
  <pre><code>fail: Microsoft.EntityFrameworkCore.Database.Connection[20004]
        An error occurred using the connection to database '' on server 'localhost'.
  An error occurred using the connection to database '' on server 'localhost'.
  System.InvalidOperationException: An exception has been raised that is likely due to a transient failure. Consider enabling transient error resiliency by adding 'EnableRetryOnFailure()' to the 'UseMySQL' call.
  </code></pre>
  
  <p>When I call the <code>EnableRetryOnFailure();</code> function as required, I am facing this exception:</p>
  
  <blockquote>
    <p>fail: Microsoft.EntityFrameworkCore.Database.Connection[20004]
          An error occurred using the connection to database '' on server 'localhost'. An error occurred using the connection to database '' on
    server 'localhost'.</p>
  </blockquote>
  
  <p>What could be the issue?
  Where am I getting it wrong?</p>
  
  <p>If you have links to useful articles about using <code>MySQL Database</code> with <code>ASP.NET Core</code> I would appreciate or your help on this particular issue.</p>
  
  <p>I am using <strong>Visual Studio IDE 2019</strong> and <strong>ASP.NET Core 3.1.1</strong></p>
  
  <p><strong>Additional Code:</strong></p>
  
  <p>This is the Startup.cs Class:</p>
  
  <blockquote>
  <pre><code>private IConfiguration _configuration;
  public Startup(IConfiguration configuration)
  {
      _configuration = configuration;
  }
  
  // This method gets called by the runtime. Use this method to add services to the container.
  public void ConfigureServices(IServiceCollection services)
  {
      services.AddControllersWithViews();
  
      // database connection string configuration  
      services.AddDbContextPool&lt;AppDBContext&gt;(options =&gt; options.UseMySql(_configuration.GetConnectionString("DatabaseConnectionString"),
          mySqlOptionsAction: options =&gt; { options.EnableRetryOnFailure(); }
          ));
  
      services.AddMvc();
  }
  </code></pre>
  </blockquote>
  
  <p><strong>This is the connection string in appsettings.json:</strong></p>
  
  <blockquote>
  <pre><code>  "ConnectionStrings": {
      "DatabaseConnectionString": "Server=localhost;Database=MyAppDB;user=root;Password=123;"
    }
  </code></pre>
  </blockquote>