The error that you are getting indicates that the calling program has a time limit and that the time limit is insufficient for the query that you are calling.
The default timeout for an
SqlConnection
is 30 seconds. You can override this be setting the timeout in the connection string definition. In traditional Net Framework this would be done in either the
app.config
file or the
web.config
file for an ASP.NET website (
broken out to several lines for viewability)
<configuration>
<connectionStrings>
<add name="nmConn" connectionString="Server=nmServer; Database=nmDB;
User Id=nmUser; Password=pwUser;
Connection Timeout=60" />
</connectionStrings>
</configuration>
Similar to the
SqlConnection, there is also a timeout for the individual
SqlCommand
. This would be updated within the block of code that is calling the actual command. Here is an example in C#
string connString = "";
string cmdText = "";
using (SqlConnection conn = new SqlConnection(connString)) {
conn.Open();
SqlCommand cmd = new SqlCommand(cmdText, conn);
cmd.CommandTimeout = 60;
try { cmd.ExecuteNonQuery(); }
catch (SqlException sx) {
}
}
References:
Microsoft Docs: Configuration Files Connection Strings[
^]
Microsofy Doc: Sql Command Connection Timeout[
^]
This is all find and dandy, but many times this is just a bandage for another problem. Proper troubleshooting should determine
Why is this happening
Find out which command is having the problem and then try that out in an SQL IDE such as
Sql Server Management Studio and see how long it actually takes to run. There are tools within there that can help you (such as Show Execution Plan) which can show what is slowing it down and sometimes has possible fixes (such as missing indexes).