开发者

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

开发者 https://www.devze.com 2023-03-21 01:21 出处:网络
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 re

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.

开发者_JAVA百科

Any clue would be appreciated.


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.


You could include a WAITFOR command in your SQL batch.

Or, you could add a lot of data, and query over non-indexed columns, that's sure to make it slow.

0

精彩评论

暂无评论...
验证码 换一张
取 消