文章主要介紹了Sql Server 數(shù)據(jù)庫中調(diào)用dll文件的過程,非常不錯(cuò),具有一定的參考借鑒價(jià)值,感興趣的朋友跟隨小編一起學(xué)習(xí)吧
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ì)大家有所幫助
- Sql Server 數(shù)據(jù)庫獲取字符串中小寫字母的SQL語句
- Sql Server數(shù)據(jù)庫如何去掉內(nèi)容里面的Html標(biāo)簽
- SQL Server數(shù)據(jù)庫遠(yuǎn)程更新目標(biāo)表數(shù)據(jù)的存儲(chǔ)過程
- MsSql 數(shù)據(jù)庫使用sqlplus創(chuàng)建DDL和DML操作方法
- SQL Server常見問題介紹及快速解決建議
- SQL Server中Table字典數(shù)據(jù)的查詢SQL示例代碼
- SQL SERVER 2012數(shù)據(jù)庫自動(dòng)備份的方法
- 關(guān)于SQL server2008調(diào)試存儲(chǔ)過程的完整步驟
- SQL Server數(shù)據(jù)庫調(diào)整表中列的順序操作方法及遇到問題
- SQL Server中的SELECT會(huì)阻塞SELECT相關(guān)資料
分享到:
投訴收藏