简体   繁体   English

消息:6528,在数据库“XYZ”的 SQL 目录中找不到程序集“XYZCLRDatabase”

[英]msg: 6528, Assembly 'XYZCLRDatabase' could not be found in the SQL catalog for database 'XYZ'

I executed the following command to my database and it give me the message Commands completed successfully.我对我的数据库执行了以下命令,它给我消息命令成功完成。

USE XYZ
GO
DECLARE @clrName nvarchar(4000) = 'XYZCLRDatabase, ...';
DECLARE @asmBin varbinary(max) = <bindary>;
DECLARE @hash varbinary(64);

SELECT @hash = HASHBYTES('SHA2_512', @asmBin);

EXEC sys.sp_add_trusted_assembly @hash = @hash,
                                @description = @clrName;
GO

It also shows the same record into the sys.trusted_assemblies table.它还在sys.trusted_assemblies表中显示相同的记录。

But it does not listed into the Assemblies folder...但它没有列在 Assemblies 文件夹中......

XYZ database > Programmability > Assemblies XYZ 数据库 > 可编程性 > 程序集

When I am trying to create the Stored Procedures with the following code I get the error.当我尝试使用以下代码创建存储过程时出现错误。

USE XYZ
GO
CREATE PROCEDURE SPName @sqlXml XML, @flag1 bit, @flag2 bit, @id int null, @flag3 bit
AS
EXTERNAL NAME XYZCLRDatabase.StoredProcedures.MYClrSP

I get the following error message:我收到以下错误消息:

Msg 6528, Level 16, State 1, Procedure SPName, Line 1 [Batch Start Line 23]
Assembly 'XYZCLRDatabase' could not be found in the SQL catalog for database 'XYZ'.

what goes wrong....出了什么问题....

While bradbury9 is correct that the CREATE ASSEMBLY statement is missing, PLEASE DO NOT enable TRUSTWORTHY in your database,!!虽然 bradbury9 认为缺少CREATE ASSEMBLY语句是正确的,但不要在您的数据库中启用TRUSTWORTHY ,!! Not only is it an unnecessary security risk, it's also absolutely useless when either using "trusted assemblies" or the much preferred signing the assemblies.它不仅是不必要的安全风险,而且在使用“受信任的程序集”或更喜欢的程序集签名时也绝对没有用。 Both of those cases ("trusted assemblies" and signing the assemblies) exist so that you don't need to set the database to TRUSTWORTHY ON (meaning: either set TRUSTWORTHY ON XOR sign the assemblies / add them as "trusted assemblies"; doing either one of the latter options means that you do not set TRUSTWORTHY ON ).这两种情况(“可信程序集”和签署程序集)都存在,因此您不需要将数据库设置为TRUSTWORTHY ON (意思是:要么设置TRUSTWORTHY ON XOR签署程序集/将它们添加为“可信程序集”;做后一个选项中的任何一个都意味着您没有设置TRUSTWORTHY ON )。 For more info on why you shouldn't enable TRUSTWORTHY and the preferred alternative (ie Module Signing ), please see:有关为什么不应启用TRUSTWORTHY和首选替代方案(即Module Signing )的更多信息,请参阅:

PLEASE, Please, please Stop Using Impersonation, TRUSTWORTHY, and Cross-DB Ownership Chaining 拜托,拜托,请停止使用模拟、可信和跨数据库所有权链接

Additionally, "trusted assemblies", while not nearly as bad as TRUSTWORTHY ON , isn't ideal either as there are several problems with that feature .此外,“可信程序集”虽然不像TRUSTWORTHY ON那样糟糕,但也不是理想的,因为该功能存在多个问题 Signing the assemblies, either outside of SQL Server (preferred) or even inside SQL Server, is far better.在 SQL Server 外部(首选)或什至在 SQL Server 内部对程序集进行签名要好得多。 Please see my answer to the following question, also here on SO, for your best options (see the bottom half, below the line):请参阅我对以下问题的回答,也在 SO 上,以获得最佳选择(请参阅下半部分,在线下方):

CLR Strict Security on SQL Server 2017 SQL Server 2017 上的 CLR 严格安全性

You are missing the CREATE ASSEMBLY instruction.您缺少CREATE ASSEMBLY指令。 In summary, the steps to add an assembly in SQL Server are:综上所述,在SQL Server中添加程序集的步骤是:

  1. Make sure the SQL Server instance allows CLR: EXEC sp_configure 'clr enabled', 1; RECONFIGURE;确保 SQL Server 实例允许 CLR: EXEC sp_configure 'clr enabled', 1; RECONFIGURE; EXEC sp_configure 'clr enabled', 1; RECONFIGURE;

    This step (#1) should only be required once.此步骤 (#1) 应该只需要一次。

  2. Call the sp_add_trusted_assembly stored procedure调用sp_add_trusted_assembly存储过程

  3. Call the CREATE ASSEMBLY instruction调用CREATE ASSEMBLY指令

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM