Sql Server 数据库中调用dll文件的过程
1.首先新建一个空的解决方案,并添加一个类库,代码如下,编译并生产dll
using System; using System.Collections.Generic; using System.Data.SqlTypes; using System.Linq; using System.Text; namespace TEST { public class TestTrans { [Microsoft.SqlServer.Server.SqlFunction] public static SqlString GenerateDecryptString(string name) { string decode = string.Empty; decode = string.Format("HELLO WORLD {0}!", name);//DecryptString(dataXML.Value); SqlString sqlValue = new SqlString(decode); return sqlValue; } } }
2.启用CLR功能
默认情况下,SQL Server中的CLR是关闭的,所以我们需要执行如下命令打开CLR:
exec sp_configure 'clr enabled',1 reconfigure Go
3.将程序集引用到数据库中
CREATE ASSEMBLY testHelloWorld FROM 'C:\TEST.dll' --('C:/TEST.dll'w为错误写法)
4.创建函数
CREATE FUNCTION dbo.clrHelloWorld ( @name as nvarchar(200) ) RETURNS nvarchar(200) AS EXTERNAL NAME testHelloWorld.[TEST.TestTrans].GenerateDecryptString
5.调用函数
SELECT dbo.clrHelloWorld('耿耿')
6.执行结果
HELLO WORLD 耿耿!
总结
相关推荐
bleach00 2020-11-10
林德强之原创 2020-08-13
PlumRain 2020-08-03
bob于 2020-07-26
dataminer 2020-06-25
neverstopforcode 2020-06-18
zxznsjdsj 2020-06-16
langyue 2020-06-13
huangyx 2020-06-11
鲁氏汤包王 2020-06-11
LWLWLiang 2020-05-28
wkwanglei 2020-05-26
Coohx 2020-04-13
thunderstorm 2020-05-09
Andrea0 2020-05-04
数据库工具开发 2020-04-25
tlsmile 2020-04-24
helencoder 2020-04-10