AditYa
AditYa

Reputation: 897

How can I rename an RDS SQL Server Web Edition's DB name (Not the RDS instance name, but one of the DB's inside the RDS instance)?

I have tried to rename the DB name in a RDS with SSMS but its giving below error.

User does not have permission to alter database 'DB name', the database does not exist, or the database is not in a state that allows access checks. (Microsoft SQL Server, Error: 5011)

Can some one please help me on this?

Upvotes: 4

Views: 2468

Answers (1)

AditYa
AditYa

Reputation: 897

I have went through many articles and aws docs but did not find straight away solution so I am writing this, hope it helps someone. After some amendments to the findings, I was able to fix this issue.

Run the below queries as master on new query terminal.

use master
ALTER DATABASE YourOldDBname
SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
EXEC rdsadmin.dbo.rds_modify_db_name N'YourOldDBname', N'YourNewDBname'
GO
ALTER DATABASE YourNewDBname
SET MULTI_USER
GO

If you have any active connection, you might get below error. Mostly you will not get any error as you are running above queries, if you still seeing below error please shut down any server that might be trying to establish a connection to same RDS DB.

Msg 50000, Level 16, State 2, Procedure rds_modify_db_name, Line 95 https://forums.aws.amazon.com/
The database could not be exclusively locked to perform the operation.

Hope its helped you :)

Upvotes: 7

Related Questions