I have an Azure Function app. I have enabled MySQLin App feature. My function is written in C# using EF Core. When attempting to establish a connection using MYSQLCONNSTR_localdb as documented, I get an exception in the logs.
This is my code to create the DBContext:
public partial class MyContext : DbContext
{
public static MyContext Factory(string connectionString)
{
//String returned from MYSQLCONNSTR_localdb
//Database=localdb;Data Source=127.0.0.1:50249;User Id=azure;Password=****
var options = new DbContextOptionsBuilder<MyContext >()
.UseMySql(builder.ConnectionString)
.Options;
return new MyContext (options);
}
}
When executing the following, I get the following exception: 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.
using var dbcontext = MyContext.Factory(settings.ConnectionString);
var result = dbcontext.Database.CanConnect();