I have a .Net application that is creating a new database. The current code is working great in development environment and in many production environments. So I am confident the code is fine.
However, we have a specific instance where the user is getting a timeout while the application is running the following SQL Command:
CREATE DATABASE NameOfDatabase
The code is pretty simple, and as you can see it uses the default timeout period for SQL commands which is 30 seconds:
using (SqlConnection connection = new SqlConnection(connectionString))
{
string query = "CREATE DATABASE " + databaseName;
SqlCommand command = new SqlCommand(query, connection);
connection.Open();
command.ExecuteNonQuery();
}
Note: our log file shows the error occurs on ExecuteNonQuery
which suggests that this is NOT a timeout while opening the connection, and rather during query execution.
The specific .Net error is:
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
With a line from the stack trace to show my reasoning on it being a command timeout (not a connection timeout):
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
Note: This error information is obtained using a try/catch around the code which was left out of the question for simplicity as it is not relevant to the problem.
Questions
Under any reasonable (or even uncommon) situations, should a
CREATE DATABASE
query take this long to run and still be successful?If it shouldn't take that long, what are the common causes for a timeout? (where should I be looking to debug the problem?)