tags:

views:

49

answers:

4

I've written an application that connects to a system over the network and logs events from that system to a SQL Server database.

I need to test the behaviour of the application when the SQL Server goes down. Is there a way to Kill just the one Database on a SQL Server system without affecting the others?

If not is there a way to simulate the SQL Server going down.

It shouldn't matter but the app is written in Java.

+3  A: 

You can use sqlcmd to set the database in single-user mode or detach the database using T-SQL. This will simulate the database going offline in a controlled fashion, but not simulate the server going down in an uncontrolled fashion, which perhaps could be more useful.

bzlm
Or take it offline: http://stackoverflow.com/questions/3574205/simulate-sql-server-database-going-down/3574259#3574259
bzlm
+1  A: 

Extending @bzlm's answer:

USE master
GO
ALTER DATABASE YourDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
abatishchev
+1  A: 

you can make the database offline

ALTER DATABASE YourDatabase SET OFFLINE
GO
SQLMenace
A: 

In addition to the other answers: You might even want to test different failure modes.

The other answers simulate the DB going down, while the server the DB runs on stays up.

You might for example also want to simulate a network failure or a server crash; this could probably be done by altering the network settings on the app server, or just by pulling its (network) plug.

Of course, whether this makes sense depends on your app.

sleske
I con't pull the network plug as the app I'm testing logs messages from a different network service to the DB. Pulling the plug stops the messages coming in. I could Isolate the code and run it without the network component for testings sake though.
Omar Kooheji