Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1004645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:09:57+00:00 2026-05-16T08:09:57+00:00

ANSWER: I wasn’t clearing my ConnectionPools. The solved scenario is: SetUp: Check to see

  • 0

ANSWER: I wasn’t clearing my ConnectionPools.

The solved scenario is:

SetUp:

  1. Check to see if the ‘TEMP_NUnit’ database (SQL Server 2005) exists on the local instance
  2. If it exists, drop it.
  3. Create a new blank database named ‘TEMP_NUnit’.

Test:

  1. Instantiate the ‘Upgrade Database’ component.
  2. Check that essential properties of component are defaulting correctly.
  3. Point the component at the blank database and call .Upgrade()
  4. Check that the upgrade actually worked

TearDown:

  1. SqlConnection.ClearAllPools();
  2. Drop the ‘TEMP_NUnit’ database.

Original question is below the fold.


Hi All

The test scenario is:

SetUp:

  1. Check to see if the ‘TEMP_NUnit’ database (SQL Server 2005) exists on the local instance
  2. If it exists, drop it.
  3. Create a new blank database named ‘TEMP_NUnit’.

Test:

  1. Instantiate the ‘Upgrade Database’ component.
  2. Check that essential properties of component are defaulting correctly.
  3. Point the component at the blank database and call .Upgrade()
  4. Check that the upgrade actually worked

TearDown:

  1. 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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T08:09:58+00:00Added an answer on May 16, 2026 at 8:09 am

    Ah, but you forgot to do this little thing before dropping the database:

    SqlConnection.ClearAllPools();
    

    By default the connection pool will maintain a connection to the database, even if you closed it before. Doing SqlConnection.ClearAllPools() will actually force all connections to be closed. You can then connect to master and drop the temp database.

    It has caused me quite an amount of grief before 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a C++ newbie, but I wasn't able to find the answer to this
ANSWER: If you ever see these lines and are mistified like I was, here's
Edit: I initially accepted thejh's answer, but I wasn't really satisfied with it since
This has been asked , but wasn't answered. The answer (use /warn:1 ) doesn't
Actually a simple question, but I wasn't able to find any good conclusive answer.
EDIT @mootinator has done awesome work with this. See his answer below. Since I
This answer says that Linq is targeted at a slightly different group of developers
An answer to a Stack Overflow question stated that a particular framework violated a
In answer to this question Joel Coehoorn said Finally, only after the site's gone
An answer to one of my questions included the following line of code: label

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.