Chicken and egg problem (restore database) when trying to write unit test against SQl Server 2008.
- by Hamish Grubijan
Ok, they are not unit tests but end-to-end tests. The setup is somewhat involved. Unit tests will use C#, ODBC connection. Every unit tests will try to clean up after itself, but every 20 tests or so (once per C# class) we would need to do a full database restore. I do not think I can do it over an ODBC connection, according to this document:
http://www.sql-server-performance.com/articles/dba/Obtain_Exclusive_Access_to_Restore_SQL_Server_p1.aspx
Msg 6104, Level 16, State 1, Line 1
Cannot use KILL to kill your own
process.
However, I would like to, so that 199 tests do not go amok because of a bad clean-up. Is there another way? Perhaps I can open a different "connection" such as use COM automation or something of that sort, and then kill all database connections from there? If so, how can I do that?
Also, will the clients be able to re-connect automatically after a restore, or would I have to dismantle everything once every 20 tests or so?
If you find this question confusing, please let me know what your questions are. Thanks!