SQL调用dll

1.启用CLR功能

EXEC sp_configure 'clr enabled' , '1';
RECONFIGURE;

2.给程序分配权限

USE '数据库';
GO
CREATE ASYMMETRIC KEY SQLCLRTestKey FROM EXECUTABLE FILE = 'D:\U8SOFT\UAP\RUNTIME\SendMails.dll'
CREATE LOGIN SQLCLRTestLogin FROM ASYMMETRIC KEY SQLCLRTestKey
GRANT EXTERNAL ACCESS ASSEMBLY TO SQLCLRTestLogin;
GO

3.将程序集引用到数据库中

CREATE ASSEMBLY SQLCLRTest
FROM 'D:\U8SOFT\UAP\RUNTIME\SendMails.dll'
WITH PERMISSION_SET = UNSAFE;

4.创建函数

CREATE FUNCTION dbo.SQLCLRTest
(
@toMial as nvarchar(max),
@Subject as nvarchar(max),
@Body as nvarchar(max)
)
RETURNS nvarchar(200)
AS EXTERNAL NAME SQLCLRTest.[SendMails.SendMailClass].MailSender

5.调用函数

select master.dbo.SQLCLRTest(@cVenEmail,@Subject,@body)

6.dll文件编译注意

方法上面 引用 [SqlFunction]

你可能感兴趣的:(sql,数据库,oracle)