Simulate Timeout - WAITFOR - C# Thread.Sleep() Equivalent
Here we look at WAITFOR.
WAITFOR can be used to make a SQL query wait an amount on time. Although you probably don't want to be using this in a production environment, I find it very handy in development when I would like to simulate a timeout with the SQL query so I can handle the error either in C# or in Javascript, and WAITFOR allows one to do this.
C# Thread.Sleep()
If your using C#, you may know of Thead.Sleep(), which will make the process (or thread) effectively pause what it is doing, wait the specified time span, and once this has passed, the process will continue onto the next line of code. Well WAITFOR is the SQL equivalent of Thread.Sleep.
WAITFOR
So in SQL Server, we have WAITFOR. Let's see an example
In this example, we use WAITFOR to wait for 45 seconds before continuing execution onto the next SQL command. Perfect to simulate the 30 second timeout in a .NET Web Application:
WAITFOR DELAY '00:00:45';