将 db_denydatawriter 角色分配给用户 dbo
当我尝试执行此操作时,我收到以下错误消息:
为 DatabaseRole“db_denydatawriter”添加成员失败。 (微软.SqlServer.Smo)
附加信息:
执行 Transact-SQL 语句或批处理时发生异常。 (Microsoft.SqlServer.ConnectionInfo)
无法使用保留用户或角色名称“dbo”。 (Microsoft SQL Server,错误:15405)
我有一个数据库需要保持“冻结”状态。 我想维护数据库的所有权,但要防止自己(作为 dbo)意外修改数据。还有其他方法可以实现此目的吗?
编辑:我决定打开 新问题 的角色,用于解决以下几行:
数据库中的数据需要保持冻结状态。然而,结构可能会改变。
数据库实际上是几个数据库。它们本质上是每半年拍摄一次的生产数据库快照。然后,用户可以通过从前端 GUI 切换后端数据库来查看历史数据。但是,有时新字段会添加到当前数据库的表中。如果前端期望这些字段存在,这可能会导致问题。我们当前的解决方案是动态添加字段(用户具有 db_datareader、db_denydatawriter 和 db_ddladmin 角色)。这意味着数据库不能设为只读,因为这会阻止对表结构的更改。
When I try to do this I receive the following error message:
Add member failed for DatabaseRole 'db_denydatawriter'. (Microsoft.SqlServer.Smo)
ADDITIONAL INFORMATION:
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
Cannot use the reserved user or role name 'dbo'. (Microsoft SQL Server, Error: 15405)
I have a database that needs to remain 'frozen'. I want to maintain ownership of the database, but prevent myself (as dbo) from accidentally modifying the data. Is there another way to accomplish this?
EDIT: I've decided to open a new question to address the lines below:
The data in the database needs to remain frozen. However, the structure might change.
The database is actually several databases. They are essentially snapshots of the production database taken semi-annually. Users are then able to view historical data by switching the back-end database from the front-end GUI. However, sometimes new fields get added to the tables in the current database. This can cause problems if the front-end expects these fields to be present. Our current solution is to add the fields on the fly (users have db_datareader, db_denydatawriter, and db_ddladmin roles). What this means is that the database cannot be made read-only because that would prevent changes to the table structure.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将数据库设置为只读:
ALTER DATABASE [db_name] SET READ_ONLY
set the db to read only:
ALTER DATABASE [db_name] SET READ_ONLY