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

  • Home
  • SEARCH
  • 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 691785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:34:55+00:00 2026-05-14T02:34:55+00:00

I am attempting to drop and recreate a database from my CI setup. But

  • 0

I am attempting to drop and recreate a database from my CI setup. But I’m finding it difficult to automate the dropping and creation of the database, which is to be expected given the complexities of the db being in use. Sometimes the process hangs, errors out with “db is currently in use” or just takes too long. I don’t care if the db is in use, I want to kill it and create it again. Does some one have a straight shot method to do this? alternatively does anyone have experience dropping all objects in the db instead of dropping the db itself?

USE master

--Create a database
IF EXISTS(SELECT name FROM sys.databases
    WHERE name = 'mydb')
BEGIN
 ALTER DATABASE mydb
 SET SINGLE_USER --or RESTRICTED_USER
 --WITH ROLLBACK IMMEDIATE
    DROP DATABASE uAbraham_MapSifterAuthority
END

CREATE DATABASE mydb;
  • 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-14T02:34:55+00:00Added an answer on May 14, 2026 at 2:34 am

    We use Hudson to rebuild staging sites for our QA team all the time. We kill connections, drop the database, then restore/rebuild/remigrate a DB.

    This is what I use to kill connections so I can drop a DB.

    USE MASTER
    GO
    IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_KillDatabaseProcesses]') AND type in (N'P', N'PC'))
       DROP PROCEDURE [dbo].[sp_KillDatabaseProcesses]
    GO
    CREATE PROCEDURE dbo.sp_KillDatabaseProcesses(@databaseName varchar(100))     
       AS
       DECLARE @databaseId int,
               @sysProcessId int,
               @cmd varchar(1000)
       EXEC ('USE MASTER')
       SELECT @databaseId = dbid FROM master..sysdatabases
          WHERE [name] = @databaseName
       DECLARE sysProcessIdCursor CURSOR FOR
          SELECT spid FROM [master]..[sysprocesses] WHERE [dbid] = @databaseId
    
       OPEN sysProcessIdCursor
       FETCH NEXT FROM sysProcessIdCursor INTO @sysProcessId WHILE @@fetch_status = 0
       BEGIN
          SET @cmd = 'KILL '+ convert(nvarchar(30),@sysProcessId)
          PRINT @cmd
          EXEC(@cmd)
          FETCH NEXT FROM sysProcessIdCursor INTO @sysProcessId
       END
       DEALLOCATE sysProcessIdCursor
    GO
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to populate a drop down from an Nhibernate object, but having problems
I have a web form that I am attempting to implement dynamic drop down
Attempting to print out a list of values from 2 different variables that are
Attempting to deploy a MOSS solution to a UAT server from dev server for
When attempting to open a project from source control on a newly formatted pc,
I'm attempting to put a few drop down menus inside of an a4j:repeat. The
I'm attempting to repopulate a drop down menu. I'm making an ajax call to
I'm attempting to make a dynamic drop down that will be filled by a
I'm attempting to allow my users to drag and drop certain rows of data
I'm attempting to use this plugin, which turns a select list into a combo

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.