Kirsten
Kirsten

Reputation: 18160

Application can open .mdf with no log file but Management Studio can not attach

I installed the DevExpress demo

C:\Users\Public\Documents\DevExpress Demos 15.2\DevExtreme\DXHotels

The demo came with HotelDB.mdf in the App_Data folder.

Out of curiosity I attempted to open the HotelDB.mdf by attempting to attach it using SQL Server 2012 Express Management Studio

However I got an error about a missing log file when I did this.

When I ran the application from the solution the log file created and I was able to subsequently attach using SQL Server.

Why was the application able to open the file when Management Studio could not?

Upvotes: 1

Views: 225

Answers (2)

Alan Macdonald
Alan Macdonald

Reputation: 1900

When you choose the mdf file to attach in management studio, the lower box (Database Details) in the UI will show both the mdf you selected and an expected ldf file which of course does not exist.

You can select the ldf file and remove this by pressing the remove button.

Once you remove the ldf file it should attach successfully. It's not very intuitive.

Upvotes: 1

M.Ali
M.Ali

Reputation: 69554

Try one of the following ......

CREATE DATABASE HotelDB
ON (FILENAME = N'C:\App_Data\HotelDB.mdf')  --<-- The path to your .mdf
FOR ATTACH_REBUILD_LOG
GO

OR

CREATE DATABASE HotelDB
ON  (FILENAME = N'C:\App_Data\HotelDB.mdf')  --<-- The path to your .mdf
FOR ATTACH
GO

Upvotes: 1

Related Questions