database - 在 SQL Azure 上使用 EF6 MainContextDropInitializer 时超时

标签 database entity-framework azure azure-sql-database

我在 SQL Azure 上有一个数据库,当我运行自动化单元测试时,我尝试删除该数据库并重新创建它。

上下文的构造函数是:

public MainContext(bool dropDB)
            : base("Main")
        {

            Database.CommandTimeout = 300;
            this.Configuration.LazyLoadingEnabled = true;
            System.Data.Entity.Database.SetInitializer<MainContext>(new MainContextDropInitializer());

            this.Database.Connection.StateChange += Connection_StateChange;
        }

但是,当尝试执行代码时,我不断收到以下错误:

Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

数据库本身很小,因此将命令超时设置为 300 就足够了。有趣的是,此问题仅在我们将 Azure DB 升级到 v12 后才发生。

有什么想法吗?

最佳答案

您看过这个文档 https://msdn.microsoft.com/en-us/data/dn456835.aspx 吗?它讨论了如何使用 sqlazure 执行策略来执行瞬时故障处理和重试。

关于database - 在 SQL Azure 上使用 EF6 MainContextDropInitializer 时超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32865354/

相关文章:

mysql - 如果 int 列达到最大值会怎样?

database - 如何导入 mysql 转储?

c# - 从具有多对多关系的实体中删除对象

azure - 高级威胁防护 REST API 不起作用

php - 在 Laravel 框架中拆分字符串

mysql - Oracle 与 MySQL - 聚合函数

c# - bool LINQ 问题

c# - LINQ to Entities 尝试投影两个表并将它们聚合

c# - 通过 URL 运行 Azure Webjob

node.js - 使用 docker 镜像的 Azure Linux 应用服务中的 Mongo 连接错误