tags:

views:

315

answers:

8

I need to test some asp.net code that handles timeout exceptions from a call to mssql database.

I'm about to reduce my CommandTimeout parameter on the connection however this might cause the errors before reaching the my code.

Is their a simple way to cause the database to timeout 'on cue'?

A: 

Write a procedure that loops for ever doing some complex task with each iteration...and if that is not enough further expand it by calling the stored procedure recursively!

Andrew Siemer
A: 

Ive cheaped this by unplugging my ethernet cable lol...

Chalkey
+1  A: 

Begin a transaction in a management studio SQL window, update the table, and don't commit it:

BEGIN TRAN
UPDATE table SET ...

This will lock any website attempt to read that table.

russau
Really messy compared to using waitfor
Sam Saffron
nice.. i had never seen that before. defn not something i've _needed_ before! :)
russau
Unfortunatly I'm working with a shared database. Will try this next time i have my own local though.
sre
+1  A: 

Couldn't you just throw the exception that you want in whatever try block you want to test?

opello
A: 

write down the procedure or Query which take more than 30 seconds to execute and call this from asp.net code.

KuldipMCA
A: 

Begin your test, then turn off your database server (sc stop "MSSQL$SQLEXPRESS" or something).

Seth
+5  A: 

What you are looking for sir is the WAITFOR command, database timeouts on queue whenever you feel like it.

Sam Saffron
Added a waitfor delay to the sql being called. Bit dissapointed I can't just raise an exception when a certain clasue is met in sql.
sre
A: 

You might consider replacing the DB connection with a mock, that could simplify your testing.

In this case, the mock would simply always signal a timeout.

sleske