13.请您于SQL Server Management Studio中执行以下的程序代码,以便使用create ASSEMBLY陈述式来登录组件SayHello.dll,然后使用create PROCEDURE陈述式建立一个会参考所登录之组件SayHello.dll的存储过程:
USE 北风贸易;
GO
IF exists (select * FROM sys.procedures where [name] = ’SayHello’)
drop PROCEDURE SayHello;
GO
IF exists (select * FROM sys.assemblies where [name] = ’SayHello’)
drop ASSEMBLY SayHello;
GO
-- 登录组件 SayHello.dll(请务必确认组件所在路径正确)
create ASSEMBLY SayHello
FROM ’C:\SQL2005Demo\CH13\SayHello\SayHello\bin\SayHello.dll’
WITH permission_set = Safe; |
GO ﹂──>组件的位置路径
-- 建立一个会参考所登录之组件 SayHello.dll 的存储过程
create PROCEDURE dbo.SayHello
(
@Greeting nvarchar(80) OUTPUT
)
AS EXTERNAL NAME SayHello.[SayHello.SayHelloClass].SayHello;
GO ↓
[命名空间.类别名称]
GO
IF exists (select * FROM sys.procedures where [name] = ’SayHello’)
drop PROCEDURE SayHello;
GO
IF exists (select * FROM sys.assemblies where [name] = ’SayHello’)
drop ASSEMBLY SayHello;
GO
-- 登录组件 SayHello.dll(请务必确认组件所在路径正确)
create ASSEMBLY SayHello
FROM ’C:\SQL2005Demo\CH13\SayHello\SayHello\bin\SayHello.dll’
WITH permission_set = Safe; |
GO ﹂──>组件的位置路径
-- 建立一个会参考所登录之组件 SayHello.dll 的存储过程
create PROCEDURE dbo.SayHello
(
@Greeting nvarchar(80) OUTPUT
)
AS EXTERNAL NAME SayHello.[SayHello.SayHelloClass].SayHello;
GO ↓
[命名空间.类别名称]
14.请您继续于SQL Server Management Studio中执行以下的程序代码,以便尝试执行我们所建立的CLR存储过程(执行结果如图表6所示):
图表5
USE 北风贸易;
GO
exec sp_configure ’clr enabled’, ’1’;
GO
RECONFIGURE;
GO
DECLARE @return_value int, @Greeting nvarchar(80);
-- 执行CLR存储过程并取得传回值与输出变量的值
execute @return_value = dbo.SayHello
@Greeting = @Greeting OUTPUT;
-- 检视传回值与输出变数的值
select @return_value AS 传回值,
@Greeting AS "输出参数 @Greeting 之值";
GO
exec sp_configure ’clr enabled’, ’1’;
GO
RECONFIGURE;
GO
DECLARE @return_value int, @Greeting nvarchar(80);
-- 执行CLR存储过程并取得传回值与输出变量的值
execute @return_value = dbo.SayHello
@Greeting = @Greeting OUTPUT;
-- 检视传回值与输出变数的值
select @return_value AS 传回值,
@Greeting AS "输出参数 @Greeting 之值";