SQLServer 無法啟動 原因為修改磁碟代碼所導致 SQLServer could not be started due to changing the drive letter

今天接到一個測試機,因為磁碟名稱被改動,

導致安裝原來位於 E 磁碟目前變成 D 磁碟,

使得 SQLServer 無法啟動,

下面就來筆記解決過程…


1. 打開Sql Server Configuration Manager,調整 SQLServer 服務的啟動參數,從原本 E:\ 更新為 D:\

錯誤記錄拋出位置也要修改

2. 打開 CMD,將服務開啟

net start mssqlserver /f /T3608

 

3. 登入SQLServer 查詢原本 master、model、msdb、tempdb 的檔案位置,並修改為新位置

SELECT name, physical_name AS current_file_location  
FROM sys.master_files  
WHERE database_id IN (DB_ID('master'), DB_ID('model'), DB_ID('msdb'), DB_ID('tempdb'));
go

 

ALTER DATABASE tempdb MODIFY FILE( NAME = tempdev , FILENAME = 'D:\MSSQL14.MSSQLSERVER\MSSQL\DATA\tempdb.mdf' ) 
ALTER DATABASE tempdb MODIFY FILE( NAME = templog , FILENAME = 'D:\MSSQL14.MSSQLSERVER\MSSQL\DATA\templog.ldf' ) 
ALTER DATABASE model MODIFY FILE( NAME = modeldev , FILENAME = 'D:\MSSQL14.MSSQLSERVER\MSSQL\DATA\model.mdf' ) 
ALTER DATABASE model MODIFY FILE( NAME = modellog , FILENAME = 'D:\MSSQL14.MSSQLSERVER\MSSQL\DATA\modellog.ldf' ) 
ALTER DATABASE msdb MODIFY FILE( NAME = MSDBData , FILENAME = 'D:\MSSQL14.MSSQLSERVER\MSSQL\DATA\MSDBData.mdf' ) 
ALTER DATABASE msdb MODIFY FILE( NAME = MSDBLog , FILENAME = 'D:\MSSQL14.MSSQLSERVER\MSSQL\DATA\MSDBLog.ldf' ) 
go

 

4. 檢查非系統資料庫的位置,是否對應到舊檔案位置

SELECT name FROM sys.databases WHERE name NOT IN ('master','msdb','tempdb','model');
go

若需要修改

ALTER DATABASE name MODIFY FILE ( NAME = filename , FILENAME = 'newfilelocation' ) 
go

 

5. 重啟 SQLServer 服務,結束!

net stop mssqlserver
net start mssqlserver

 

 

參考資料:

Microsoft SQLServer 移動系統資料庫

張貼留言

0 留言