温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

SQL中CRL函数如何使用

发布时间:2021-06-25 16:51:07 来源:亿速云 阅读:185 作者:Leah 栏目:数据库

本篇文章为大家展示了SQL中CRL函数如何使用,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。

在SQL中使用CRL函数

实验目标:

1. 在SQL中创建CRL函数,使之能够向指定的计算机发送消息

实验步骤

2. 在VS中创建类发送消息的类

3. 将以下代码黏贴进去

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);

}

}

}

点击“生成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("防火墙安全错误!", "错误",

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 --在数据库中引入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

可以看到注册的程序集

go --创建函数

create function dbo.crlHelloWord

(

@ipaddress as nvarchar(100),

@message as nvarchar(100)

)

returns nvarchar(200)

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

运行客户端程序,在SQL执行以下命令,可以发现该函数能够想客户端发送消息

select dbo.crlHelloWord('10.7.10.199','你已经删除了条记录')

上述内容就是SQL中CRL函数如何使用,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI