--1、默认情况下,SQL Server中的CLR是关闭的,所以我们需要执行如下命令打开CLR:
exec sp_configure 'clr enabled',1
reconfigure
GO
-- DROP FUNCTION dbo.fnScoketSend --删除Function
-- drop assembly SqlDependency --删除Dependency
-- create assembly SqlDependency FROM 'E:\SqlDependency.dll' WITH PERMISSION_SET = UNSAFE --1、创建clr依赖
CREATE FUNCTION dbo.fnScoketSend --2、创建Function
(
@Content as nvarchar(MAX)
)
RETURNS nvarchar(MAX)
AS EXTERNAL name [SqlDependency].[SqlDependency.Notice].[ScoketSendContent]
--DROP TRIGGER dbo.notify_trigger
-- 3、创建表触发器
CREATE TRIGGER notify_trigger ON [dbo].[Sample]
AFTER INSERT, DELETE, UPDATE
AS
BEGIN
/*
update触发器会在更新数据后,
将更新前的数据保存在deleted表中,更
新后的数据保存在inserted表中。
*/
DECLARE @UpdateID NVARCHAR(20)
DECLARE @UpdateContent Varchar(MAX)
SET @UpdateID=(SELECT Deleted.Id FROM Deleted)
SET @UpdateContent=(SELECT Inser
SqlServer开启CLR使用(C#)DLL实现实时Socket通知
最新推荐文章于 2025-06-18 09:04:51 发布