Database cannot be upgraded because it is read-only or has read-only files. Make the database or files writeable, and rerun recovery

MxL*_*evs 11 sql-server ssms attach

I have received a database file and the instructions for loading it is to install SQL Server 2005 and then attach it using SQL Server Management Studio.

After installing everything, I tried to attach the MDF file but then it tells me:

the directory lookup for the file "D:{folderName}{filename}.LDF" failed with the operating system error 21 (error not found)

An LDF file did not come with the database, so presumably it should be generated automatically.

Now, D drive is where my CD drive is, so it's not going to find anything there. Nor is it going to have any luck trying to create anything there.

  1. Why is it trying to look for a log file at a specific path? Why not where the database file is?

  2. How can I attach this database?

I realized that when I select a database to attach, three entries appear under "database details". an MDF, NDF, and LDF. The LDF's "current file path" points to the D drive path above, so I removed it.

This time, when I hit "OK", I get a different error message:

Database cannot be upgraded because it is read-only or has read-only files.
Make the database or files writeable, and rerun recovery.

File activation Failure. The physical name D:{folder}{file}.LDF may be incorrect.
New log file "..." was created. (Microsoft SQL Server, Error: 3415)

So now it creates a new log file in the same folder as the database file, which is great, but it seems like there are security issues.

Additional information:

  • 这些说明要求我使用登录名“sa”,它似乎是 sysadmin 帐户。我使用该登录名连接到我的 SQL Server 实例。

  • 我已经检查了它不是只读的文件属性。该目录也不是只读的。允许所有 ACL。

  • 我无法附加数据库。当我尝试附加它时,它会抛出一条错误消息“附加数据库失败”。

  • 关闭 SSMS 并以管理员身份重新打开它没有任何区别。

  • select SERVERPROPERTY('ProductVersion')返回 9.00.4035.00。数据库附带了另一个名为“dbdata.ini”的文件,上面写着“IsSql2000=1”,所以大概是打算在 SQL Server 2000 中加载它。我会看看我是否可以让它在 2000 上工作。

小智 33

我刚刚找到了一个回答这个问题的帖子:

这可能不适用于所有情况,但我尝试安装语义搜索数据库并遇到相同的错误。

您必须以管理员身份运行 SQL Server Management Studio,它才能工作。


Mik*_*Fal 11

这不是访问问题。问题是您将数据库.mdf附加到比最初附加到的实例更高版本的 SQL Server并且它是只读的。SQL Server 正在尝试将数据库升级为附加的一部分,但无法升级,因为 db 处于只读模式。

如果您的数据库在READ_ONLY(根据您的错误消息听起来就是这种情况),那么您需要根据 Technet 文档将所有文件(日志和数据)附加到数据库中。如果您查看该FOR ATTACH条款,它明确描述了:

...对于只读数据库,由于无法更新主文件,因此无法重建日志。因此,当您附加日志不可用的只读数据库时,您必须在FOR ATTACH子句中提供日志文件或文件。

您需要随附.ldf数据库。我会联系提供数据库的人,并要求他们提供.mdf.ldf文件。然后,您可以使用以下语法附加它:

CREATE DATABASE [foo]
ON (FILENAME='<<path to mdf>>')
LOG ON (FILENAME='<<path to ldf>>')
FOR ATTACH;
Run Code Online (Sandbox Code Playgroud)

READ_ONLY状态,不能从数据库中不附加它,因为它被存储在数据库中的元数据中删除。要更改它,数据库需要联机并附加。

另一种选择是要求备份数据库。如果您正在执行数据库还原而不是附加,则可以更轻松地解决其中一些问题。

  • 将“LOG ON”与匹配的“ldf”一起使用并没有解决我的问题 (2认同)

小智 10

  1. 打开我的电脑。
  2. 找到保存“.mdf”和“.ldf”文件的主文件夹。
  3. 右键单击文件夹,单击“属性”。
  4. 在属性窗口中单击“安全”
  5. 点击“编辑”按钮
  6. 为列出的用户启用“读取和执行”、“读取”、“写入”,并将更改应用于以下文件夹,直到数据库文件。
  7. 尝试附加“.mdf”文件