如果要使用特定的数据库中不存在的程序集,请使用存储过程在SQL Server 2008 R2中创建一个程序集,并提供文件的路径作为参数。
USE DBName
GO
CREATE PROCEDURE spCreateAssembly
@FilePath varchar(max)
AS
BEGIN
IF NOT EXISTS (select 1 from sys.assembly_files f
full outer join sys.assemblies a on f.assembly_id=a.assembly_id
full outer join sys.assembly_modules m on a.assembly_id=m.assembly_id
WHERE a.name = 'Lib1')
BEGIN
sp_configure 'show advanced options', 1
RECONFIGURE
GO
sp_configure 'clr enabled', 1
RECONFIGURE
GO
sp_configure 'show advanced options', 0
RECONFIGURE
GO
Create Assembly Lib1 from @FilePath with Permission_set = SAFE
END
END
但是出现错误:
消息102,级别15,状态1,过程spCreateAssembly,第14行 'sp_configure'附近的语法不正确。
答案 0 :(得分:1)
尝试一下:
CREATE PROCEDURE spCreateAssembly
@FilePath varchar(max)
AS
BEGIN
IF NOT EXISTS (select 1 from sys.assembly_files f
full outer join sys.assemblies a on f.assembly_id=a.assembly_id
full outer join sys.assembly_modules m on a.assembly_id=m.assembly_id
WHERE a.name = 'Lib1')
BEGIN
EXEC sp_configure 'show advanced options', 1
RECONFIGURE
EXEC sp_configure 'clr enabled', 1
RECONFIGURE
EXEC sp_configure 'show advanced options', 0
RECONFIGURE
Create Assembly Lib1 from @FilePath with Permission_set = SAFE
END
END
您不能在存储过程中使用GO
。