问题
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?
回答1:
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
回答2:
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.
来源:https://stackoverflow.com/questions/34970307/application-can-open-mdf-with-no-log-file-but-management-studio-can-not-attach