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

非 Y 不嫁゛ 提交于 2019-12-13 01:41:43

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!