Am正在连接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.rnCREATE 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。