简体   繁体   中英

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

Am connecting azure sql from visual studio 2019.

I try to create database from VS. but its showing following error.

 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.

MY Code

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();

Like @mjwills said, please try increase cmd.CommandTimeout value. Set the time in seconds to wait for the command to execute. The default is 30 seconds.

Ref here: SqlCommand.CommandTimeout Property : Gets or sets the wait time (in seconds) before terminating the attempt to execute a command and generating an error.

HTH.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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