使用存储过程创建程序集
Create assembly using stored procedure
我想在 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
但是出现错误:
Msg 102, Level 15, State 1, Procedure spCreateAssembly, Line 14
Incorrect syntax near 'sp_configure'.
试试这个:
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
。
我想在 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
但是出现错误:
Msg 102, Level 15, State 1, Procedure spCreateAssembly, Line 14 Incorrect syntax near 'sp_configure'.
试试这个:
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
。