Solved

Rename SQL Server 2005 Database question

Posted on 2011-03-22
4
547 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
  • 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

914 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now