Search This Blog

Unable to open the physical file in SQL

                Unable to open the physical file in SQL

Issue-Issue in SQL while Attaching MDF File or Restoring Backup file from some location.

Error1
Msg 5120, Level 16, State 101, Line 1
Unable to open the physical file "C:\ DB \AdventureWorksDW2012_Data (1).mdf". Operating system error 2: "2(The system cannot find the file specified.)".

Error 2
Msg 5120, Level 16, State 101, Line 1
Unable to open the physical file "C:\ DB \AdventureWorksDW2012_Data.mdf". Operating system error 32: "32(failed to retrieve text for this error. Reason: 15105)".


Issue Description-While attaching the Database  mdf file in sql server we were getting these above errors.

--Attaching MDF File without ldf file
CREATE DATABASE AdventureWorksDW2012
ON (FILENAME = 'C:\DB\AdventureWorksDW2012_Data.mdf')
FOR ATTACH_REBUILD_LOG ;

Error

Msg 5120, Level 16, State 101, Line 1
Unable to open the physical file "C:\DB\AdventureWorksDW2012_Data (1).mdf". Operating system error 2: "2(The system cannot find the file specified.)".

Issue Solution

-Run SSMS as an Administrator
-Restart SQL Server

Now you will be able to attach the DB Successfully.

Run your query again 

--Attaching MDF File without ldf file
CREATE DATABASE AdventureWorksDW2012
ON (FILENAME = 'C:\DB\AdventureWorksDW2012_Data.mdf')
FOR ATTACH_REBUILD_LOg

Output.It will attach the mdf file and will create a new ldf (log file) in same location 
with the message below.

File activation failure. The physical file name "C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\AdventureWorksDW2012_log.ldf" may be incorrect.
New log file 'C:\DB\AdventureWorksDW2012_log.ldf' was created.

NOTE: If after Running SQL as Administrator and Restarting the sql server won’t work for you then check for permission in your folder where you have kept your mdf or back file then go to “Sharing and Security of that folder and Allow-Full control.

1 comment:

  1. AnyConv is a new free online document converter service. AnyConv will convert your documents from one format to another. AnyConv

    ReplyDelete