Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...