Sql Server 數(shù)據(jù)庫中調(diào)用dll文件的過程
1.首先新建一個(gè)空的解決方案,并添加一個(gè)類庫,代碼如下,編譯并生產(chǎn)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功能
默認(rèn)情況下,SQL Server中的CLR是關(guān)閉的,所以我們需要執(zhí)行如下命令打開CLR:
exec sp_configure 'clr enabled',1 reconfigure Go
3.將程序集引用到數(shù)據(jù)庫中
CREATE ASSEMBLY testHelloWorld FROM 'C:\TEST.dll' --('C:/TEST.dll'w為錯(cuò)誤寫法)
4.創(chuàng)建函數(shù)
CREATE FUNCTION dbo.clrHelloWorld ( @name as nvarchar(200) ) RETURNS nvarchar(200) AS EXTERNAL NAME testHelloWorld.[TEST.TestTrans].GenerateDecryptString
5.調(diào)用函數(shù)
SELECT dbo.clrHelloWorld('耿耿')
6.執(zhí)行結(jié)果
HELLO WORLD 耿耿!
總結(jié)
以上所述是小編給大家介紹的Sql Server 數(shù)據(jù)庫中調(diào)用dll文件的過程,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)本站網(wǎng)站的支持!
版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。
關(guān)注官方微信