最后说一下CLR存储过程的部署: Create proc 存储过程名 as EXTERNAL NAME 数据库中Assembly名称.程序集中Assembly名称.程序方法名。
注意,如果你的程序中有命名空间的话,要这样写:
Create proc 存储过程名 as EXTERNAL NAME 数据库中Assembly名称.“程序命名空间.程序集中Assembly名称”.程序方法名。
下面的SQL是创建CLR程序集和CLR存储过程的SQL语句,假设我们编译好的dll位于C:/CLRDemo.dll,我们的程序没有命名空间(默认情况下,新建的SQL工程都没有命名空间,请注意) use pubs go create assembly CLRDemoAssemly from 'c:/CLRDemo.dll' go create proc USP_SayHello as EXTERNAL NAME CLRDemoAssemly.StoredProcedures.USP_SayHello go create proc USP_SayHelloByParameter (@Msg nvarchar(128)) as EXTERNAL NAME CLRDemoAssemly.StoredProcedures.USP_SayHelloByParameter go create proc USP_SayHelloByReturn (@Msg nvarchar(128)) as EXTERNAL NAME CLRDemoAssemly.StoredProcedures.USP_SayHelloByReturn go create proc USP_ExecuteBySqlCommand (@Id nvarchar(4),@Name nvarchar(32)) as EXTERNAL NAME CLRDemoAssemly.StoredProcedures.USP_ExecuteBySqlCommand go create proc USP_ExecuteByExecuteAndSend (@Id nvarchar(4),@Name nvarchar(32)) as EXTERNAL NAME CLRDemoAssemly.StoredProcedures.USP_ExecuteByExecuteAndSend go create proc UPS_PipeSendSqlDataRecord as EXTERNAL NAME CLRDemoAssemly.StoredProcedures.UPS_PipeSendSqlDataRecord go create proc UPS_PipeSendResultSqlDataRecord as EXTERNAL NAME CLRDemoAssemly.StoredProcedures.UPS_PipeSendResultSqlDataRecord go
调用方式: exec USP_SayHello go exec USP_SayHelloByParameter 'Hello,TJVictor again' go declare @Result int exec @Result=USP_SayHelloByReturn 'Hello,TJVictor again' select @Result go exec USP_ExecuteBySqlCommand '1234','Test USP_ExecuteBySqlCommand' go exec USP_ExecuteByExecuteAndSend '5678','Test USP_ExecuteByExecuteAndSend' go exec UPS_PipeSendSqlDataRecord go exec UPS_PipeSendResultSqlDataRecord go
删除方式:注意删除Assembly时,一定要先把引用此Assembly的所有东西删除。 drop proc USP_SayHello drop proc USP_SayHelloByParameter drop proc USP_SayHelloByReturn drop proc USP_ExecuteBySqlCommand drop proc USP_ExecuteByExecuteAndSend drop proc UPS_PipeSendSqlDataRecord drop proc UPS_PipeSendResultSqlDataRecord go drop assembly CLRDemoAssemly