溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

SQL中CRL函數(shù)如何使用

發(fā)布時(shí)間:2021-06-25 16:51:07 來(lái)源:億速云 閱讀:192 作者:Leah 欄目:數(shù)據(jù)庫(kù)

本篇文章為大家展示了SQL中CRL函數(shù)如何使用,內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過(guò)這篇文章的詳細(xì)介紹希望你能有所收獲。

在SQL中使用CRL函數(shù)

實(shí)驗(yàn)?zāi)繕?biāo):

1. 在SQL中創(chuàng)建CRL函數(shù),使之能夠向指定的計(jì)算機(jī)發(fā)送消息

實(shí)驗(yàn)步驟

2. 在VS中創(chuàng)建類發(fā)送消息的類

3. 將以下代碼黏貼進(jìn)去

using System;

using System.Collections.Generic;

using System.Text;

using System.Net.Sockets;

using System.IO;

namespace ClassLibrary1

{

public class Class1

{

public static string classscoket(string IPaddress, string mes)

{

string msg = mes;

string IPadd = IPaddress;

TcpClient tcpc = new TcpClient(IPadd, 5656);

NetworkStream tcpStream = tcpc.GetStream();

StreamWriter reqStreamW = new StreamWriter(tcpStream);

reqStreamW.Write(msg);

reqStreamW.Flush();

tcpStream.Close();

tcpc.Close();

return (mes);

}

}

}

點(diǎn)擊“生成ClassLibrary“

4. 新建接收消息的客戶端

添加引用

using System;

using System.Collections.Generic;

using System.Text;

using System.Net.Sockets;

using System.Windows.Forms;

namespace MessClient1

{

class Program

{

static void Main(string[] args)

{

try

{

TcpListener tcpl = new TcpListener(5656);

tcpl.Start();

while (true)

{

Socket s = tcpl.AcceptSocket();

Byte[] stream = new Byte[80];

int i = s.Receive(stream);

string message = System.Text.Encoding.UTF8.GetString(stream);

MessageBox.Show(message);

}

}

catch (System.Security.SecurityException)

{

MessageBox.Show("防火墻安全錯(cuò)誤!", "錯(cuò)誤",

MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

}

catch (Exception)

{

}

}

}

}

5. 在中的配置

exec sp_configure 'clr enable',1

go

reconfigure

go

use personnel

go

alter database personnel set trustworthy on

go --在數(shù)據(jù)庫(kù)中引入dll

create assembly [System.Net.Sockets] from 'C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\ClassLibrary1\ClassLibrary1\bin\Debug\ClassLibrary1.dll'

with permission_set=unsafe

可以看到注冊(cè)的程序集

go --創(chuàng)建函數(shù)

create function dbo.crlHelloWord

(

@ipaddress as nvarchar(100),

@message as nvarchar(100)

)

returns nvarchar(200)

as EXTERNAL NAME [System.Net.Sockets].[ClassLibrary1.Class1].classscoket

運(yùn)行客戶端程序,在SQL執(zhí)行以下命令,可以發(fā)現(xiàn)該函數(shù)能夠想客戶端發(fā)送消息

select dbo.crlHelloWord('10.7.10.199','你已經(jīng)刪除了條記錄')

上述內(nèi)容就是SQL中CRL函數(shù)如何使用,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI