ANSWER: I wasn't clearing my ConnectionPools.
The solved scenario is:
SetUp:
- Check to see if the 'TEMP_NUnit' database (SQL Server 2005) exists on the local instance
- If it exists, drop it.
- Create a new blank database named 'TEMP_NUnit'.
Test:
- Instantiate the 'Upgrade Database' component.
- Check that essential properties of component are defaulting correctly.
- Point the component at the blank database and call .Upgrade()
- Check that the upgrade actually worked
TearDown:
SqlConnection.ClearAllPools();
- Drop the 'TEMP_NUnit' database.
Original question is below the fold.
Hi All
The test scenario is:
SetUp:
- Check to see if the 'TEMP_NUnit' database (SQL Server 2005) exists on the local instance
- If it exists, drop it.
- Create a new blank database named 'TEMP_NUnit'.
Test:
- Instantiate the 'Upgrade Database' component.
- Check that essential properties of component are defaulting correctly.
- Point the component at the blank database and call .Upgrade()
- Check that the upgrade actually worked
TearDown:
- Drop the 'TEMP_NUnit' database.
Everything's going fine until I get to the TearDown phase. I always get the following error:
Cannot drop database "TEMP_NUnit" because it is currently in use.
This is confusing me, because I'm closing (explicitly calling conn.Close in finally statements) and disposing (via using statement) all my DbConnection objects correctly. There shouldn't be anything running on the "TEMP_NUnit" database by the time the TearDown comes around.
If I close NUnit and then re-open it, step 2 of the SetUp always works first go.
I'm not sure what I'm doing wrong here. Any pointers in the right direction would be appreciated.