繁体   English   中英

Microsoft Azure Sql 从 VS 2019 连接时连接速度很慢 C#

[英]Microsoft Azure Sql connection is slow while connect from VS 2019 C#

我正在从 Visual Studio 2019 连接 azure sql。

我尝试从 VS 创建数据库。 但它显示以下错误。

 Execution Timeout Expired.  The timeout period elapsed prior to completion of the operation or the 
server is not responding.\r\nCREATE DATABASE operation failed. Internal service error.

我的代码

SqlConnectionStringBuilder xconstr = new SqlConnectionStringBuilder();
xconstr.DataSource = "xxxx.database.windows.net";
xconstr.UserID = "xxxxx";
xconstr.Password = "xxxxxx";
xconstr.InitialCatalog = "xx";
xconstr.ConnectTimeout = 360;
SqlConnection con = new SqlConnection(xconstr.ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("CreateDatabase ", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@dbname", dbname);
cmd.ExecuteNonQuery();
con.Close();

就像@mjwills 所说,请尝试增加cmd.CommandTimeout值。 以秒为单位设置等待命令执行的时间。 默认值为 30 秒。

参考这里: SqlCommand.CommandTimeout 属性:获取或设置在终止尝试执行命令并生成错误之前的等待时间(以秒为单位)。

HTH。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM