sobota, 29 września 2012

Unable to open the physical file "D:\pm\somedb.mdf". Operating system error 5: "5(error not found)".

Today I encountered this message on my screen. I love this kind of errors - error not found.  So here is the solution how to fix it, just follow the steps and  save your time



Run the script:

declare @sqlser varchar(20)
EXEC master..xp_regread @rootkey='HKEY_LOCAL_MACHINE',@key='SYSTEM\CurrentControlSet\Services\MSSQL$SQLEXPRESS',
@value_name='objectname', @value=@sqlser OUTPUT
PRINT 'Account Starting SQL Server Service:' +convert(varchar(30),@sqlser)


If you don't see  results, then run regedit and go to the specified path and find the account.

Then.

  • Right click on the folder with your db files and click on properties 
  • Click on security tab
  • Click on Add button and add account = the same you have found in regedit
  • Provide modify privilege


To attach db just use the code:

USE [master]
GO
CREATE DATABASE [name] ON
( FILENAME = N'D:\tmp\name.mdf' ),
( FILENAME = N'D:\tmp\name_log.ldf' )
FOR ATTACH
GO
IF EXISTS ( SELECT name
FROM master.sys.databases sd
WHERE name = N'name'
AND SUSER_SNAME(sd.owner_sid) = SUSER_SNAME() )
EXEC [name].dbo.sp_changedbowner @loginame=N'sa',
@map=false
GO


Brak komentarzy:

Prześlij komentarz