SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


database stuck in single user and no spid


database stuck in single user and no spid

Author
Message
icampbell
icampbell
Valued Member
Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)

Group: General Forum Members
Points: 52 Visits: 277
Hi i have a dev database that is stuck in single user mode
when i try and access the database i can't a connection already in use.
However when i use exec sp_who - no connections are displayed against the database.

How can i get out of this please?w00t As i would like to overwrite this database with the live database.
Sudhakar Vallamsetty
Sudhakar Vallamsetty
SSC Journeyman
SSC Journeyman (95 reputation)SSC Journeyman (95 reputation)SSC Journeyman (95 reputation)SSC Journeyman (95 reputation)SSC Journeyman (95 reputation)SSC Journeyman (95 reputation)SSC Journeyman (95 reputation)SSC Journeyman (95 reputation)

Group: General Forum Members
Points: 95 Visits: 77
Try this and see if it fixes ur problem.

use Master
Go
select * from master.sys.sysprocesses
where spid>50 -- don't want system sessions
and dbid = DB_ID(name of database in question)

--Find the SPID which is making connection to your single_user mode DB and KIll it
Kill 100 -- replace 100 with the SPID which you get from the above query

ALTER database 'your DB name' set MULTI_USER with ROLLBACK IMMEDIATE

*******Cool
Sudhakar
icampbell
icampbell
Valued Member
Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)

Group: General Forum Members
Points: 52 Visits: 277
Sudhakar Vallamsetty (9/17/2012)
Try this and see if it fixes ur problem.

use Master
Go
select * from master.sys.sysprocesses
where spid>50 -- don't want system sessions
and dbid = DB_ID(name of database in question)

--Find the SPID which is making connection to your single_user mode DB and KIll it
Kill 100 -- replace 100 with the SPID which you get from the above query

ALTER database 'your DB name' set MULTI_USER with ROLLBACK IMMEDIATE

Hi Sudhakar,

I already tried this and there are no open connections listed against the database


paul.knibbs
paul.knibbs
SSCrazy
SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)

Group: General Forum Members
Points: 2511 Visits: 6232
Are you using SQL Management Studio to issue these commands? It has an annoying tendency of opening multiple connections to the database, so you'd be better off using SQLCMD to test this out.
prasanna.vinay
prasanna.vinay
SSC-Enthusiastic
SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)

Group: General Forum Members
Points: 120 Visits: 204
i hope you can also use "sp_dboptions '<DBName>' 'multiuser' 'true'"
icampbell
icampbell
Valued Member
Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)

Group: General Forum Members
Points: 52 Visits: 277
in the end had to get someone to log into server with sys admin user and detach and then re-attach database.

Thanks for the tip about the management studio. Next time i will try sqlcmd
Nils Gustav Stråbø
Nils Gustav Stråbø
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2427 Visits: 3575
You can also see who is holding a lock on the database by querying sys.dm_tran_locks.

Kill the session_id and change to multi user by executing ALTER DATABASE db SET MULTI_USER.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search