ASP.NET Core 1.1 中的 Azure SetExecutionStrategy
Azure SetExecutionStrategy in ASP.NET Core 1.1
当我尝试更新网格中的多个字段时出现此错误:
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.
我可以找到一个可能的解决方案 here,但不确定如何将下面建议的代码 (EF6+) 转换为 .Net Core 版本。
public class MyConfiguration : DbConfiguration
{
public MyConfiguration()
{
SetExecutionStrategy("System.Data.SqlClient", () => new SqlAzureExecutionStrategy());
}
}
public class MyConfiguration : DbConfiguration
{
public MyConfiguration()
{
SetExecutionStrategy(
"System.Data.SqlClient",
() => new SqlAzureExecutionStrategy(1, TimeSpan.FromSeconds(30)));
}
}
我在 DbConfiguration 行和 SetExecutionStrategy 上遇到错误(需要参考?)
如果有人知道如何将其转换为 .Net Core,请向我展示步骤或代码片段,我将不胜感激。谢谢!
在 EF Core 中,您可以在派生上下文的 OnConfiguring 方法或 Startup.cs 中使用以下内容:
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder
.UseSqlServer(
@"Server=(localdb)\mssqllocaldb;Database=EFMiscellanous.ConnectionResiliency;Trusted_Connection=True;",
options => options.EnableRetryOnFailure());
}
当我尝试更新网格中的多个字段时出现此错误:
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.
我可以找到一个可能的解决方案 here,但不确定如何将下面建议的代码 (EF6+) 转换为 .Net Core 版本。
public class MyConfiguration : DbConfiguration
{
public MyConfiguration()
{
SetExecutionStrategy("System.Data.SqlClient", () => new SqlAzureExecutionStrategy());
}
}
public class MyConfiguration : DbConfiguration
{
public MyConfiguration()
{
SetExecutionStrategy(
"System.Data.SqlClient",
() => new SqlAzureExecutionStrategy(1, TimeSpan.FromSeconds(30)));
}
}
我在 DbConfiguration 行和 SetExecutionStrategy 上遇到错误(需要参考?)
如果有人知道如何将其转换为 .Net Core,请向我展示步骤或代码片段,我将不胜感激。谢谢!
在 EF Core 中,您可以在派生上下文的 OnConfiguring 方法或 Startup.cs 中使用以下内容:
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder
.UseSqlServer(
@"Server=(localdb)\mssqllocaldb;Database=EFMiscellanous.ConnectionResiliency;Trusted_Connection=True;",
options => options.EnableRetryOnFailure());
}