0

我有一对 CLR 程序集,我正在尝试创建一个可重复的实现脚本。两个程序集都需要 EXTERNAL 权限集,所以我还涉及到非对称密钥,这些都会导致问题。当您第二次运行它时,您会收到“无法删除密钥,登录映射到它”错误。

我有其他一些问题是:我需要数据库和服务器级别的登录名/密钥吗?

目前我的脚本是:

USE master
GO 

IF EXISTS (SELECT * FROM sys.database_principals WHERE name = 'BaselCLRLogin')
    DROP LOGIN [BaselCLRLogin]
GO

IF EXISTS (SELECT * FROM sys.asymmetric_keys WHERE name = 'BaselCLRKey')
    DROP ASYMMETRIC KEY [BaselCLRKey]
GO

USE [BaselST]
GO

IF EXISTS (SELECT * FROM sys.objects WHERE OBJECT_ID = OBJECT_ID('clr.CheckFileFormat'))
    DROP PROCEDURE clr.CheckFileFormat
GO

IF  EXISTS (SELECT * FROM sys.database_principals WHERE name = N'BaselCLRLogin')
    DROP USER [BaselCLRLogin]
GO

IF  EXISTS (SELECT * FROM sys.assemblies asms WHERE asms.name = N'BaselCLR' and is_user_defined = 1)
    DROP ASSEMBLY [BaselCLR]
GO

IF EXISTS (SELECT * FROM sys.asymmetric_keys WHERE name = 'BaselCLRKey')
    DROP ASYMMETRIC KEY [BaselCLRKey]
GO

USE master
GO 

-- First Create the Asymmetric Key from the Assembly
CREATE ASYMMETRIC KEY BaselCLRKey
FROM EXECUTABLE FILE = 'D:\BASEL\BS_Assemblies\BaselCLR.dll'
GO

-- Create the Login from the Asymmetric Key
CREATE LOGIN BaselCLRLogin FROM ASYMMETRIC KEY BaselCLRKey
GO

-- Grant the External Access Priviledge to the Login
GRANT EXTERNAL ACCESS ASSEMBLY TO BaselCLRLogin
GO

USE [BaselST] 
GO

IF NOT EXISTS(SELECT * FROM sys.schemas WHERE name = 'clr')
    EXEC ('CREATE SCHEMA [clr]')
GO

-- Add a database user in the SQLCLR_Net Database for the Login
CREATE USER [BaselCLRLogin] FOR LOGIN [BaselCLRLogin]
GO

CREATE ASSEMBLY BaselCLR
FROM 'D:\BASEL\BS_Assemblies\BaselCLR.dll'
WITH PERMISSION_SET = EXTERNAL_ACCESS
GO

CREATE PROCEDURE clr.CheckFileFormat(
    @fileName nvarchar(255)
    , @seperator nvarchar(1)
    , @lineTerminator tinyint
    , @encoding tinyint
    , @headerFieldCount int
    , @bodyFieldCount int
    , @footerFieldCount int
    , @reason nvarchar(max) out)
AS
EXTERNAL NAME BaselCLR.StoredProcedures.CheckFileFormat
GO

如果还有什么我做过的不,不让我知道!

4

2 回答 2

1

The problem is in the following line...

IF EXISTS (SELECT * FROM sys.database_principals WHERE name = 'BaselCLRLogin')

You're looking for the login name in the wrong system table!

Select from sys.syslogins instead.

IF EXISTS (SELECT * FROM sys.syslogins WHERE [sid] = SUSER_SID('BaselCLRLogin'))
    DROP LOGIN [BaselCLRLogin]
GO
于 2015-02-11T09:52:39.510 回答
0

您必须使用不同的密钥对每个程序集进行签名。

于 2012-09-11T10:14:09.347 回答