February 7, 2007 at 3:43 pm
I have a database RB_Data_Services_MSCRM that I put in a single user mode by
Alter database RB_Data_Services_MSCRM
set single_user with rollback immediate;
Now I cannot get it back into multi-user mode, delete it or rename it.
If I try enterring
Alter database RB_Data_Services_MSCRM
set single_user with rollback immediate;
I get a message saying:
Msg 5064, Level 16, State 1, Line 1
Changes to the state or options of database 'rb_data_services_mscrm' cannot be made at this time. The database is in single-user mode, and a user is currently connected to it.
Msg 5069, Level 16, State 1, Line 1
ALTER DATABASE statement failed.
I am the only user on the system so I want to get this db in a state where I can either just rename it or delete it.
Any suggestions on how to do that?
Thanks for all of your help.
Rick Bellefond
February 7, 2007 at 4:05 pm
Some one is connected that db...
Do you any monitoring tools connecting to this db...
What is the error you are getting...when you try change it to multi user mode?
Try the following script...
DECLARE @ID INT
DECLARE @MSG CHAR(8), @DataName sysname
While 1 = 1
BEGIN
Set RowCount 1
SELECT
@id = spid
FROM
Master..Sysprocesses P,
Master..Sysdatabases D
WHERE
<A href="mailto.Name=@DataName">D.Name=@DataName
AND
D.dbid = P.dbid
IF @@rowcount = 0
break
SELECT @msg = 'KILL ' + convert(char(8) ,@ID)
Print @msg
EXEC( @msg)
--break
END
GO
ALTER DATABASE....
GO
MohammedU
Microsoft SQL Server MVP
February 7, 2007 at 4:21 pm
Mohammed,
When I try to put the db in multi user mode I get:
Msg 5064, Level 16, State 1, Line 1
Changes to the state or options of database 'rb_data_services_mscrm' cannot be made at this time. The database is in single-user mode, and a user is currently connected to it.
Msg 5069, Level 16, State 1, Line 1
ALTER DATABASE statement failed.
Rick Bellefond
February 7, 2007 at 4:28 pm
Mohammed when I tried your script I got the message saying
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '-' -
Was I supposed to change @DataName to the name of my db?
Thanks
Rick Bellefond
February 7, 2007 at 4:36 pm
To put it in multiuser mode you say:
If I try enterring
Alter database RB_Data_Services_MSCRM
set single_user with rollback immediate;
That is the code to put it in single_user mode, not multi_user mode. Try:
ALTER DATABASE RB_Data_Services_MSCRM
SET MULTI_USER
Also, make sure you ONLY have Query Analyzer open.
-SQLBill
February 7, 2007 at 4:39 pm
Yes... @DataName = your db name...
at the end of the procedure use your alter database statement...and make sure you use SET MULTI_USER option..
MohammedU
Microsoft SQL Server MVP
February 7, 2007 at 4:51 pm
Mohammed,
Ok, I actually got it to go into multi user mode by going to Services and restarting the SQL Server and then giving it the
Alter database RB_Data_Services_MSCRM
Set multi_user;
command and then it took it.
I then wanted to rename it and so from the Management Studio I highlighted that db and then right clicked and selected rename. I gave it another name and then when I hit the enter key I got:
TITLE: Microsoft SQL Server Management Studio
------------------------------
Unable to rename RB_Data_Services_MSCRM22. (ObjectExplorer)
------------------------------
ADDITIONAL INFORMATION:
Rename failed for Database 'RB_Data_Services_MSCRM'. (Microsoft.SqlServer.Smo)
------------------------------
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
------------------------------
The database could not be exclusively locked to perform the operation. (Microsoft SQL Server, Error: 5030)
****************************************
So how do I exclusively lock this data base so I can then rename or delete it?
Thanks.
Rick Bellefond
February 7, 2007 at 4:54 pm
Bill,
Oops, I meant to post
ALTER DATABASE RB_Data_Services_MSCRM
SET MULTI_USER
Any idea as to how I can get exclusive control over this db so I can then rename it or delete it?
Thanks.
Rick
February 7, 2007 at 8:05 pm
If you just want to be able to drop the database, use this:
use master alter database RB_Data_Services_MSCRM set offline with rollback immediate
That will kick everyone out of the database, and set it offline so that no users can connect to it. Then you can use a drop database command to delete it.
February 7, 2007 at 8:27 pm
Michael,
That is a good idea.
I will give that a try.
Thanks.
Rick Bellefond
February 7, 2007 at 11:35 pm
Again some one else in the db...
When you rename the database, sql will try to get the exclusive on the db so that it can rename it..
You can use my script to kill the connections or use ALTER DATABASE command...
immediately run the following...
EXEC sp_rename '<dbname>', '<New dbname>'
MohammedU
Microsoft SQL Server MVP
February 8, 2007 at 9:02 am
Exclusive mode pretty much means SINGLE_USER mode.
-SQLBill
February 9, 2007 at 11:38 am
Be aware that if you have Object Explorer open and focused on the database in question, that is a separate connection to the database. If you can find no other users connected to the database, then try closing object explorer.
Your best bet is to make sure that you maintain your connection to the database during the entire transaction.
Don't set it to single user, then do something else to it, then set it to multi user. Do the whole process in one transaction.
April 11, 2008 at 11:56 am
If all you want to do is rename just run this:
alter database database name set single_user with rollback immediate
go
alter database DatabaseName modify name = NewDatabaseName
go
alter database NewDatabaseName set multi_user
go
print 'enjoy'
Viewing 14 posts - 1 through 13 (of 13 total)
You must be logged in to reply to this topic. Login to reply