I added a very minor migration to my project. It just changes the data type of a couple of columns to decimal(5,2)
. The Add Migration
command generates the migration class. However, the Update-Database
command throws an exception.
Also, the Remove-Migration
throws the same exception:
An exception has been raised that is likely due to a transient failure. If you are connecting to a SQL Azure database consider using SqlAzureExecutionStrategy.
I am using a local SQL Server 2014 database. My connection string for development purposes is very simple:
"DbConnectionString": "Server=.;Database=DBNAME;Trusted_Connection=True;MultipleActiveResultSets=true"
That is stored in a config.json
file. I am using the very latest version of Visual Studio, which is VS 2017 15.8.5.
I updated the web project to .NET Core 2.1 and then in Nuget I upgraded to the latest stable 2.1.4. That caused a change in the error message which is now:
An exception has been raised that is likely due to a transient failure. Consider enabling transient error resiliency by adding
EnableRetryOnFailure()
to theUseSqlServer
call.
I went to my startup class and I did add that EnableRetryOnFailure
property even though I doubt this is the root of the problem.
services.AddDbContextPool<AppDbContext>(options => options.UseSqlServer(_configuration.GetConnectionString("DbConnectionString"), builder =>
{
builder.EnableRetryOnFailure(5, TimeSpan.FromSeconds(10), null);
}));
The generated migration class:
public partial class v50 : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<decimal>(
name: "LnRrSncsm",
table: "Jobs",
type: "decimal(5, 2)",
nullable: false,
oldClrType: typeof(float));
migrationBuilder.AlterColumn<decimal>(
name: "LnRrQsnqcsm",
table: "Jobs",
type: "decimal(5, 2)",
nullable: false,
oldClrType: typeof(float));
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<float>(
name: "LnRrSncsm",
table: "Jobs",
nullable: false,
oldClrType: typeof(decimal),
oldType: "decimal(5, 2)");
migrationBuilder.AlterColumn<float>(
name: "LnRrQsnqcsm",
table: "Jobs",
nullable: false,
oldClrType: typeof(decimal),
oldType: "decimal(5, 2)");
}
}