MSDE Detach Tricks
Closing and disposing SqlConnection objects isn’t sufficient to guarantee that you’ll be able to sp_detach_db a database your done working with. A trick that seems to work is to preceed calls to Close() with a call to ChangeDatabase(“master”).
Use exec sp_who & sp_lock with QueryAnalyzer to monitor the locks as you step through the program.