Sql server 超时已过期。在Azure sql上完成操作之前的超时时间

Sql server 超时已过期。在Azure sql上完成操作之前的超时时间,sql-server,asp.net-mvc,azure,azure-sql-database,azure-elastic-scale,Sql Server,Asp.net Mvc,Azure,Azure Sql Database,Azure Elastic Scale,我需要在global.asax应用程序启动事件上在windows azure上创建一个sql数据库,但出现以下错误: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. This failure occurred while attempting to connect to the routing destinatio

我需要在global.asax应用程序启动事件上在windows azure上创建一个sql数据库,但出现以下错误:

Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.  This failure occurred while attempting to connect to the routing destination. The duration spent while attempting to connect to the original server was - [Pre-Login] initialization=296; handshake=324; [Login] initialization=0; authentication=1; [Post-Login] complete=94;
我的代码如下:

   private void SetupSSM() {
            SqlConnectionStringBuilder connStrBldr = new SqlConnectionStringBuilder
            {
                UserID = SettingsHelper.AzureUsernamedb,
                Password = SettingsHelper.AzurePasswordDb,
                ApplicationName = SettingsHelper.AzureApplicationName,
                DataSource = SettingsHelper.AzureSqlServer
            };

            bool created=DbUtils.CreateDatabaseIfNotExists(connStrBldr.ConnectionString, SettingsHelper.Azureshardmapmgrdb);
            if(created)
            {
                Sharding sharding = new Sharding(SettingsHelper.AzureSqlServer, SettingsHelper.Azureshardmapmgrdb, connStrBldr.ConnectionString);
            }
        }



  public static bool CreateDatabaseIfNotExists(string connectionString, string databaseName)
        {
            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                conn.Open();

                SqlCommand cmd = new SqlCommand(
                    string.Format("SELECT * FROM sys.databases WHERE [name]=\'{0:S}\'", databaseName),
                    conn);

                if (cmd.ExecuteScalar() == null)
                {
                    SqlCommand cmd2 = new SqlCommand(
                        string.Format("CREATE DATABASE [{0:S}];", databaseName),
                        conn);

                    cmd2.ExecuteNonQuery();

                    return true;
                }
                else
                    return false;
            }
        }

如何增加超时>?是sql超时还是由于sql没有响应而导致的web请求超时?

您可以通过执行以下操作来设置命令超时,您看到的错误是命令超时,最有可能是您的创建数据库花费的时间超过30秒,这是默认超时值

例如,将超时设置为300秒 cmd.CommandTimeout=300


当我们遇到这个问题时,我们的数据库的电源不足。性能监视器显示,在我们得到错误的过程中,DTU已达到最大值。

。实际上我也遇到了同样的问题,我的SqlStatement.CommandTimeout设置为900秒。而且它有时还会引起问题。它似乎与Azure DB中的DTU和记录数(DB大小)有关。基本级别5DTU 2GB DB选项似乎是最差的。出于某种原因,某些SP和/或查询只是挂起而没有明显的原因,即使它们以前已经被快速执行了很多次。我认为这可能是小型Azure DBs的进程并发性问题。您应该检查DTU的使用情况并决定数据库的版本是的,我同意,但如果数据库大小保持在限制范围内,基本级别DTU(5)的性能应与高级DTU级别的性能一样好。DTU除了数据库大小之外还有其他因素,如可用内存,cpu等。这是基于每秒事务数。我真的希望它能如此简单,但例如,现在我正在从多个数据库的同一个表中删除100条记录。13个数据库被删除,没有问题,其余2个数据库仍被锁定。所有数据库都是基本的5DTU,在任何数据库或根服务器上都没有(基于用户的)并发进程。两个“冻结”DBs上的DTU%约为1.79%,而DB大小为823MB。我在这里遇到了相同的问题。使用Azure搜索,并从SQL数据库导入数据。总是在一段时间后超时。尝试增加超时,但未成功。