Solved

Rename SQL Server 2005 Database question

Posted on 2011-03-22
4
546 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

771 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

11 Experts available now in Live!

Get 1:1 Help Now