Sql Server 数据库中调用dll文件的过程
1.首先新建一个空的解决方案,并添加一个类库,代码如下,编译并生产dll
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Data.SqlTypes;
usingSystem.Linq;
usingSystem.Text;
namespaceTEST
{
publicclassTestTrans
{
[Microsoft.SqlServer.Server.SqlFunction]
publicstaticSqlStringGenerateDecryptString(stringname)
{
stringdecode=string.Empty;
decode=string.Format("HELLOWORLD{0}!",name);//DecryptString(dataXML.Value);
SqlStringsqlValue=newSqlString(decode);
returnsqlValue;
}
}
}
2.启用CLR功能
默认情况下,SQLServer中的CLR是关闭的,所以我们需要执行如下命令打开CLR:
execsp_configure'clrenabled',1 reconfigure Go
3.将程序集引用到数据库中
CREATEASSEMBLYtestHelloWorldFROM'C:\TEST.dll'--('C:/TEST.dll'w为错误写法)
4.创建函数
CREATEFUNCTIONdbo.clrHelloWorld ( @nameasnvarchar(200) ) RETURNSnvarchar(200) ASEXTERNALNAMEtestHelloWorld.[TEST.TestTrans].GenerateDecryptString
5.调用函数
SELECTdbo.clrHelloWorld('耿耿')
6.执行结果
HELLOWORLD 耿耿!
总结
以上所述是小编给大家介绍的SqlServer数据库中调用dll文件的过程,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!
热门推荐
10 对患者生日祝福语简短
11 结婚祝福语简短装备
12 周岁祝福语学生文案简短
13 订婚领证祝福语简短精辟
14 导师获奖祝福语大全简短
15 新婚购房祝福语简短精辟
16 牛年祝福语简短的爱人
17 送芒果的祝福语简短
18 送给学长毕业祝福语简短