質問

Background: I had a working database called WBPM which I renamed using the right-click feature in SSMS to WBPM_v20120530 as I wanted to roll out a new version of the database. I believe the right click rename feature of SSMS does not change the physical .MDF or .LDF file so when I wanted to publish the new version using SSDT, I had an error notifying me the WBPM LDF and MDF files existed.

I renamed the physical files using Windows Explorer. This is the procedure I followed:

-- 1. The Database had been renamed using SSMS right click FROM WBPM to WBPM_v20120530.
ALTER DATABASE WBPM_v20120530 SET OFFLINE

-- 2. I have inserted the new string "_v20120530" to the .mdf file using Windows Explorer and then run this command.
ALTER DATABASE WBPM_v20120530
MODIFY FILE (NAME = WBPM, 
FILENAME = 
'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\WBMD_v20120530_Primary.mdf')
GO

-- 3. I have inserted the new string "_v20120530" to the .ldf file and run this command.
ALTER DATABASE WBPM_v20120530 
MODIFY FILE (NAME = WBPM_log, 
FILENAME ='C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\WBPM_v20120530_Primary.ldf')
GO

-- 4. I can not bring the database Online?
ALTER DATABASE WBPM_v20120530 SET ONLINE
GO

This is the error message I get from SSMS:

Msg 5120, Level 16, State 101, Line 1
Unable to open the physical file "C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\WBMD_v20120530_Primary.mdf".
Operating system error 2: "2(failed to retrieve text for this error.
Reason: 15105)

Msg 945, Level 14, State 2, Line 1
Database 'WBPM_v20120530' cannot be opened due to inaccessible files or insufficient memory or disk space. See the SQL Server errorlog for details.

Msg 5069, Level 16, State 1, Line 1
ALTER DATABASE statement failed.

Any help would be greatly appreciated as I would like to recover the database?

Many thanks and kind regards,

Bertie.

役に立ちましたか?

解決

I followed your exact procedure and was able to do this no problem.

Please validate that the SQL Server service account has full permissions on the folder, that UAC is disabled, and that the spelling of both file names in Windows Explorer matches the file names in your alter statements.

Also try a slightly shorter file name (e.g. instead of v20120530 try just injecting v2 into the file path - you shouldn't be hitting an upper bound there but it may be worth a try.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top