Get the App
SLTechnology News&Howtos  ›  Database  › 

How to use the CRL function in SQL

Shulou Source: shulou.com Published: 2022-05-31 21:39:51 10月04日 Update

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.

Tags: Functions messages clients clients content skills knowledge programs errors creation experiments conciseness security simplicity code commands that is data databases articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Shulou Tech Info Docker macOS Shulou Information