3

I need to test some ASP.NET code that handles timeout exceptions from a call to a MS-SQL database.

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

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

8 Answers 8

10

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

Sign up to request clarification or add additional context in comments.

1 Comment

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.
3

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.

4 Comments

Really messy compared to using waitfor
nice.. i had never seen that before. defn not something i've needed before! :)
Unfortunatly I'm working with a shared database. Will try this next time i have my own local though.
I was just trying to get a timeout on an AZURE database by doing a full update of one column inside a tran (no commit or rollback) and had also set transaction isolation level to serializable. No could do... i suspect AZURE is allowing dirty reads (read uncommitted) by default. I am now looking for other solutions. Ok.. our default isolation level is read committed snapshot..(which is the last version of the row).. basically allowing a query to read the last value of the updated record> I ran "DBCC useroptions" to find out
1

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

Comments

0

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!

Comments

0

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

Comments

0

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

Comments

0

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.

Comments

-1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.