Solved

Rename SQL Server 2005 Database question

Posted on 2011-03-22
4
555 Views
Last Modified: 2012-05-11
I'm trying to rename a database and am getting the following error...
Msg 924, Level 14, State 1, Line 1
Database 'AIMSNet_Test' is already open and can only have one user at a time.
Could you please assist me I am querying against master

I am following the below steps:

I have put the database in single user mode and am trying to rename using
EXEC sp_renamedb 'AIMSNet_Test' 'AIMSNet'
GO

Then detach the database -- Detach new database from SQL Server to rename the data files
EXEC sp_detach_db @dbname = 'AIMSNet'
GO

Then rename the data files using the command prompt...cd to data file locations then
--REN AIMSNet_Test_dat.mdf AIMSNet_dat.mdf
--REN AIMSNet_Test_log.ldf AIMSNet_log.ldf

--Reattach DB and data files
--EXEC sp_attach_db @dbname = ‘AIMSNet’
--, @filename1 = ‘D:\DATA\AIMSNet_dat.mdf’
--, @filename2 = ‘E:\LOGS\AIMSNet_log.ldf’
--GO
0
Comment
Question by:chavis03
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
dba2dba earned 500 total points
ID: 35190061
Looks like the DB is in Single user mode. Follow the below thread to bring it to multi user mode.

http://www.sqlservercentral.com/Forums/Topic332162-146-1.aspx

After this is done.

In order to rename the database, you need to first kill all the connections:

select * from master..sysprocesses where dbid=db_id('DBName')

and then KILL all the SPID's

Below is the command to Rename:

EXEC sp_renamedb 'oldName', 'newName'

0
 
LVL 14

Expert Comment

by:Daniel_PL
ID: 35190311
You can also try:

ALTER DATABASE <oldname> SET RESTRICTED_USER WITH ROLLBACK IMMEDIATE
GO
EXEC sp_renamedb '<oldname>', '<newname>'
GO
ALTER DATABASE <newname> SET MULTI_USER
GO

Open in new window

0
 
LVL 14

Expert Comment

by:Daniel_PL
ID: 35190348
Or, set it back to SINGLE_USER (in last step) if there's business need to left db in that mode.
0
 

Author Comment

by:chavis03
ID: 35191105
Thanks so much for your help.....after I terminated the connections (there was a sleeping connection awaiting commands) I was able to complete everything I needed to do.  
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question