【发布时间】:2015-10-03 10:35:51
【问题描述】:
我需要在 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请求超时?
【问题讨论】:
-
我在这里遇到了同样的问题。使用 Azure 搜索,并从 SQL 数据库导入数据。一段时间后总是超时。尝试增加超时时间,但没有成功。
标签: sql-server asp.net-mvc azure azure-sql-database azure-elastic-scale