Database is read-only 的解决方法

本文介绍了解决SQL Server中因文件权限不足导致无法编辑数据的问题的方法。包括如何为IIS6.0环境下的Network Service账户设置MDF和LDF文件的读写权限,以及使用SSEUtil工具进行数据库分离的具体步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

You need Read/Write permission on both MDF and LDF in order to editing data.  If you're using IIS 6.0, you need to add Network Process account and give Read/Write permission to these two files.  You also need to detach the database before changing the permissions on the file.  You can do this using SSEUtil.exe tool:
http://www.microsoft.com/downloads/details.aspx?FamilyID=FA87E828-173F-472E-A85C-27ED01CF6B02&displaylang=en

> SSEUtil.exe -child "NT Authority/Network Service" -detach

 

Thanks,
Lan 
   
- What is Network Process Account.
>>>  This account is use by IIS6.  For more detail on the account, see
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconiis60applicationisolationmodes.asp

    - How can i create it.
>>> It should already created for you
    - What do you mean by detach.
>>> you need to detach the database to release the current info in master database; so that the next time you load the page, it load the new permission for this database
    - how can i use this tool for the same, as it is doing nothing when i have tried,
>>> here're the steps:

   1) open window explorer, go to your app_data folder of your web project (e.g. d:/mywebsite/app_data folder)
   2) select both *.mdf and *.ldf, right mouse click and click on Properties
   3) click on security tab, click "Add" button
   4) type <your Machine Name>/Network Service in the "Enter the object names to select textbox, click ok
   5) make sure Read and Write permissions checkboxes are checked and click ok
   6) open cmd window (assuming you already have a copy of SSEUtil tool)
   7) type SSEUtil -d d:/mywebsite/app_data/test.mdf  --- this step detach the database
   8) run your page

Hope that help,
Lan

1.  Delete the MDF/LDF files from the App_Data directory of the website under inetpub/wwwroot. 
2.  Download and install the SSEUTIL command line tool from:
      http://www.microsoft.com/downloads/details.aspx?FamilyID=FA87E828-173F-472E-A85C-27ED01CF6B02&displaylang=en
3.  Using sseutil, issue a command that looks something like:  sseutil -child "NT AUTHORITY/NETWORK SERVICE" -detach D:/  .  You will need to change the account name and the detach path to match your machine settings.  If on IIS5/5.1, then ASPNET will be the correct user account.  Also, you can determine the detach path pretty easily by issuing sseutil -list to see where the problematic MDFs are currently attached.  The "D:/" in the sample command line is just the first few characters that sseutil uses to auto-detach all databases that begin with "D:/".  Change the path as neeeded for your machine.
4.  Set the ACLs on App_Data directory under inetpub/wwwroot to grant R/W to the appropriate process account - NETWORK SERVICE on WS03 or ASPNET on IIS5/5.1.
5.  Re-copy the MDF/LDF files from the directory where the file-based website exists back into App_Data under inetpub/wwwroot.  After the copy occurs, check that the MDF/LDF files have now inherited the new ACLs.
6.  Re-run the application (ignore any connection errors that might occur - just hit refresh in the browser).

We are working on a fix in SSE that will eliminate the manual reconfiguration for RTM.

 


 

It's probably read only because the user that the SQL Server service runs as
only has read permissions on the files. Change the Windows permissions and
restart the database service.

### PyCharm 中解决 “This table is read-only. Changes cannot be applied” 的方法 当在 PyCharm 数据库工具中尝试修改表结构时,如果收到错误提示“This table is read-only. Changes cannot be applied”,这通常是因为数据库连接配置或权限设置存在问题。以下是可能的原因以及解决方案: #### 1. **检查数据库用户的权限** 确保当前使用的 MySQL 用户具有足够的权限来执行 `ALTER TABLE` 和其他 DDL 操作。可以通过以下 SQL 查询验证用户权限: ```sql SHOW GRANTS FOR 'your_user'@'localhost'; ``` 如果没有相应的权限,可以使用管理员账户授予必要的权限: ```sql GRANT ALTER, CREATE, DROP ON your_database.* TO 'your_user'@'localhost'; FLUSH PRIVILEGES; ``` 此操作会赋予指定用户对目标数据库的 `ALTER`, `CREATE`, 和 `DROP` 权限[^1]。 #### 2. **确认数据源是否为只读模式** 在 PyCharm 中打开数据库的数据源设置界面,导航到 `Database Tool Window -> Data Source Properties`,并检查是否存在标记为“Read Only”的选项。如果有,请取消勾选该选项以允许写入操作[^2]。 #### 3. **刷新元数据缓存** 有时 PyCharm 可能因为内部缓存而导致表显示为只读状态。在这种情况下,可以选择手动刷新元数据缓存: - 打开 Database 工具窗口。 - 使用右键菜单中的 `Invalidate Caches and Restart` 功能重新加载项目资源。 - 或者通过点击顶部工具栏上的同步按钮(两个循环箭头图标),强制更新本地缓存与实际数据库的一致性[^3]。 #### 4. **调整 JDBC 连接字符串参数** 某些时候,默认的 JDBC URL 配置可能会导致表被识别成不可编辑的状态。可以在 PyCharm 的数据源配置页面里自定义 JDBC URL 参数,加入如下内容以显式禁用只读标志: ``` ?sessionVariables=sql_mode='NO_AUTO_VALUE_ON_ZERO',default_storage_engine=INNODB&useSSL=false&serverTimezone=UTC&autoReconnect=true&rewriteBatchedStatements=true ``` #### 5. **切换存储引擎类型** 部分特殊场景下,特定类型的存储引擎可能导致表处于只读状态。例如 MyISAM 表不支持事务处理功能,而 InnoDB 则完全兼容 ACID 特性。因此建议将受影响的表转换至更通用的 InnoDB 存储引擎上运行: ```sql ALTER TABLE your_table ENGINE=InnoDB; ``` 以上措施应能够有效缓解乃至彻底消除 PyCharm 报告出来的关于表只读的相关警告信息。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值