How do you get past this sort of error: “Ad hoc updates to system catalogs are not allowed.”?

雨燕双飞 提交于 2020-01-15 10:33:31

问题


Take the following input:

update sys.assemblies set permission_set_desc = 'EXTERNAL_ACCESS' where
assembly_id = <someInt> and name not like 'microsoft%'

and the following output:

Msg 259, Level 16, State 1, Line 2
Ad hoc updates to system catalogs are not allowed.

This is in SQL Server 2012. I'm logged in as "sa", so this is probably not a user permissions issue. Links I'm finding on Google are either void of solutions or hard for me to follow. How do I get past this without producing unecessary permanent changes to the database? Thanks!

EDIT

Sorry, I accidentally copied and pasted input and output from the wrong window. I deleted what I was really having trouble with, so I'm not going to be able to find what it was. The first comment fixed whatever it was I having trouble with though. I don't remember what exactly it was now, but I was going from one thing to another pretty quickly...If I remember what I was looking at later, I'll fix the question, but I'll go ahead and handle the question as-is for now.


回答1:


You can't update the system catalogs, just like the error message said. You haven't been able to do this since SQL Server 2000, and even back in those cowboy days it was rarely a good idea. The way you need to do this, like Gordon said, is to use ALTER ASSEMBLY. If you only have a single assembly to update:

ALTER ASSEMBLY [assembly name] WITH PERMISSION_SET = EXTERNAL_ACCESS;

If you have multiple, you can generate a script using dynamic SQL:

DECLARE @sql NVARCHAR(MAX) = N'';

SELECT @sql += N'ALTER ASSEMBLY ' + QUOTENAME(name)
  + ' WITH PERMISSION_SET = EXTERNAL_ACCESS;
  '
FROM sys.assemblies WHERE assembly_id = <someInt>; -- or IN (<some range>)

PRINT @sql;
-- EXEC sp_executesql @sql;

I don't think you need to filter out the Microsoft assemblies if you've provided a specific assembly_id.



来源:https://stackoverflow.com/questions/21189469/how-do-you-get-past-this-sort-of-error-ad-hoc-updates-to-system-catalogs-are-n

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