SQL

The Microsoft SQL Server Management Studio (even v2008 R2) has problems with executing large SQL-files. To execute these files you need to use the sqlcmd Utility.

Sample usage:

sqlcmd -S myServer\instanceName -i -U loginname -P password C:\myScript.sql

Sometimes you want to catch and specially handle an SQL-Timeout.
To do this, just put a try-catch around your SQL-Call and catch the SqlException. Now check the Property Number if it is -2 (which stands for Timeout). That’s it.

Here’s a little Code Example how that could look like:

try
{
	RunSomeSqlQuery();
}
catch (SqlException ex)
{
	// Check if it's a TimeoutException
	if (ex.Number == -2)
	{
		// It is...
		// Do whatever you need
	}
	else
	{
		// Other Type of Exception, re-throw it or whatever
		throw;
	}
}

If you want to simulate a Timeout in your SQL-Statement, just use the WAITFOR DELAY SQL-Statement to block for some Time and therefore results in a Timeout.

Here’s an example to wait for 1 Minute:

WAITFOR DELAY '00:01:00'