Simulate Timeout - WAITFOR - C# Thread.Sleep() Equivalent


InterServer Web Hosting and VPS
Sony Playstation PS4 Pro Custom Build NVMe SSD Drive - Enclosure case and Crucial NVMe SSD
PS4 Pro Custom External SSD NVMe Drive

How I built a PS4 Pro Custom External SSD NVMe Drive...

NUC8i7BEH with memory
Intel NUC8I7BEH Review and Custom Build

This is my review of the Intel NUC8i7BEH and a summary of my build...

Card image cap
Asus M5A88-M EVO Review

This is my review of the Asus M5A88-M EVO motherboard...

Corsair Vengeance Blue 8GB (2x4GB) DDR3 PC3-12800C9 1600MHz Dual Channel Kit
Corsair Vengeance Blue Review

This is my review of the Corsair Vengeance Blue 8GB (2x4GB) DDR3 PC3-12800C9 1600MHz Dual Channel Kit memory...

Robotic Arm with USB PC Interface Review
Robotic Arm with USB PC Interface Review

This is my review of the Robotic Arm with USB PC Interface...

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';


Sponsored Links
SolarSystem - AngularJS Demo
SolarSystem - Angular JS Demo

Check out my first Angular JS demo hosted in Azure, it helped win my first Angular contract. Put the sound on.