Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the CRL function in SQL

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article shows you how to use the CRL function in SQL, the content is concise and easy to understand, it can definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Using CRL function in SQL

Experimental objectives:

1. Create a CRL function in SQL so that it can send messages to the specified computer

Experimental procedure

two。 Create a class in VS that sends messages

3. Paste the following code into it

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)

}

}

}

Click "generate ClassLibrary"

4. Create a new client to receive messages

Add referenc

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 ("Firewall security error!" , "error"

MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

}

Catch (Exception)

{

}

}

}

}

5. Configuration in

Exec sp_configure 'clr enable',1

Go

Reconfigure

Go

Use personnel

Go

Alter database personnel set trustworthy on

Go-introducing dll into the database

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

You can see the registered assembly

Go-create function

Create function dbo.crlHelloWord

(

@ ipaddress as nvarchar

@ message as nvarchar

)

Returns nvarchar (200)

As EXTERNAL NAME [System.Net.Sockets]. [ClassLibrary1.Class1]. Classscoket

Run the client program and execute the following command in SQL. You can find that the function can send messages to the client.

Select dbo.crlHelloWord ('10.7.10.1999' you have deleted a record')

The above is how to use the CRL function in SQL. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report