SQL Server 调用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)

C# 

6.方法上面 引用 [SqlFunction]

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