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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With