连续连接数据库时出错 [英] Error when connect database continuously

查看:105
本文介绍了连续连接数据库时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在连续循环中从数据库查询时,过了一段时间 我收到错误消息:

When I am querying from database in continuous looping, after some time I get an error :

引发了一个异常,该异常可能是由于瞬态 失败.如果要连接到SQL Azure数据库,请考虑使用SqlAzureExecutionStrategy.

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.

通常正常.

推荐答案

如果您使用的是EF Core,请在弹性连接失败时重试:

If you are using EF Core configure retry on failure for resilient connections :

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
    optionsBuilder.UseSqlServer("your_connection_string", builder =>
        {
            builder.EnableRetryOnFailure(5, TimeSpan.FromSeconds(10), null);
        });
    base.OnConfiguring(optionsBuilder);
}

这篇关于连续连接数据库时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆