共計 1837 個字符,預計需要花費 5 分鐘才能閱讀完成。
自動寫代碼機器人,免費開通
本篇文章為大家展示了 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 函數如何使用,你們學到知識或技能了嗎?如果還想學到更多技能或者豐富自己的知識儲備,歡迎關注丸趣 TV 行業資訊頻道。
向 AI 問一下細節