tags:

views:

100

answers:

5

I am using SQL Server for my web application. How will I know that an insert query failed because the database server memory disk is already full

+1  A: 

if you want to find you memory usage

exec sp_spaceused

This will give you how much memory you are used for particular database

anishmarokey
+4  A: 

The error code you will get back will indicate that the disk is full: 1105 (primary filegroup full) or 9902 (log file full)

Martin Haluza
+1  A: 

Check the error code you get back from SQL Server when you try to insert into the database.

With that error given back you can then decide what to do. (e.g. Try to insert again, Try to free up some memory on the server) Also if you havent already, place your Insert statement inside a Transaction so that you can rollback if an error occurs.

kevchadders
Actually I am finding a way yet to simulate the scenario of having a full disk. When I find a way I was hoping I could test it thorugh the exception it will throw if there's any
cedric
+2  A: 

You can simulate this by disabling the auto-grow feature on the database (It's a checkbox in the database properties on the file tab) and filling up the database. The error will be the same.

ALTER DATABASE YourDatabase
MODIFY FILE (name='YourFile' MAXSIZE=50MB);
mrdenny
Thnks for this....But is there a way to automate setting this property? Through codes would be much better
cedric
Sure, I'll put the code in my answer. You'll want to set the maxsize value to the current size of the file so that it doesn't grow any more.
mrdenny
just what i needed... This solved everything.. Thnx.. :)
cedric
No problem, glad to help.
mrdenny
+1  A: 

I suppose you can believe that if the disk is full the SQL server will return the error code :).

You can make your testing code think it is communicating with the SQL server but instead it will talk to some fake object of yours that will respond with the error codes you want to test.

There are frameworks that can help you. One of them is Rhino Mocks you can download from http://ayende.com

Martin Haluza