Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How could i limit and slow down my local SQL Express for test purpose?

I'm making a query in c# with ADO to select one record from Microsoft SQL Express database. for some test purpose I need to make a delay about 300ms with in SQL Express so that I could simulate my required situation. There is a limitations that I can not use any store procedures.

Any clue would be appreciated.

like image 557
Ehsan Zargar Ershadi Avatar asked Jul 19 '11 08:07

Ehsan Zargar Ershadi


1 Answers

You could possibly inject a WAITFOR into your SQL:

See this SO QA for more info Sleep Command in T-SQL?

Given a command sent to the database:

SELECT * FROM MyTable

Embedded in a SqlCommand:

using (var conn = new SqlConnection("connection string"))
using (var comm = new SqlCommand("", conn))
{
    conn.Open();
    comm.CommandText = "SELECT * FROM MyTable";
    comm.ExecuteNonQuery();
}

Change it to something like this:

    using (var conn = new SqlConnection("connection string"))
    using (var comm = new SqlCommand("", conn))
    {
        conn.Open();
#if DEBUG
        comm.CommandText = "WAITFOR DELAY '00:00:01.000'; SELECT * FROM MyTable";
#else
        comm.CommandText = "SELECT * FROM MyTable";
#endif
        comm.ExecuteNonQuery();
    }

To embed a 1 second wait.

Ideally you don't want to do this in such an ugly and questionable way, but for the purposes of demonstration it will suffice.

like image 193
Adam Houldsworth Avatar answered Oct 06 '22 17:10

Adam Houldsworth