如何启用clr enabled和disabled配置选项

SqlServer开启CLR使用(C#)DLL实现实时Socket通知_其它数据库-织梦者
当前位置:&>&&>& > SqlServer开启CLR使用(C#)DLL实现实时Socket通知
SqlServer开启CLR使用(C#)DLL实现实时Socket通知
--①默认情况下,SQL Server中的CLR是关闭的,所以我们需要执行如下命令打开CLR:
exec sp_configure 'clr enabled',1
reconfigure
-- DROP FUNCTION dbo.fnScoketSend
--删除Function
-- drop assembly SqlDependency
--删除Dependency
-- create assembly SqlDependency FROM 'E:\SqlDependency.dll' WITH PERMISSION_SET = UNSAFE --①创建clr依赖
CREATE FUNCTION dbo.fnScoketSend
--②创建Function
@Content as nvarchar(MAX)
RETURNS nvarchar(MAX)
AS EXTERNAL name [SqlDependency].[SqlDependency.Notice].[ScoketSendContent]
--DROP TRIGGER dbo.notify_trigger
-- ③创建表触发器
CREATE TRIGGER notify_trigger ON
[dbo].[Sample]
INSERT, DELETE, UPDATE
update触发器会在更新数据后,
将更新前的数据保存在deleted表中,更
新后的数据保存在inserted表中。
DECLARE @UpdateID NVARCHAR(20)
DECLARE @UpdateContent Varchar(MAX)
@UpdateID=(SELECT
Deleted.Id FROM
@UpdateContent=(SELECT
Inserted.UserAddr FROM
dbo.fnScoketSend(@UpdateContent)
INSERT INTO Sample(UserName,UserAddr,AddDate) VALUES('张三','深圳市南山区蛇口',GETDATE())
SELECT * FROM Sample
using Microsoft.SqlServer.S
using System.Collections.G
using System.Data.SqlT
using System.IO;
using System.L
using System.N
using System.Net.S
using System.T
using System.Threading.T
//SqlDependency.dll
namespace SqlDependency
public class Notice
[SqlFunction(IsDeterministic = true, DataAccess = DataAccessKind.Read)]
public static SqlString ScoketSendContent(SqlString Content)
string str = &&;
//创建一个Socket
var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.Connect(&121.77.61.65&, 4530);
System.Threading.Thread.Sleep(100);
var outputBuffer = Encoding.ASCII.GetBytes(&new data&);
socket.BeginSend(outputBuffer, 0, outputBuffer.Length, SocketFlags.None, null, null);
str = &传送成功&;
catch (Exception e)
str = &传送失败& + e.M
if (socket != null && socket.Connected)
//关闭双方通信
socket.Shutdown(SocketShutdown.Both);
System.Threading.Thread.Sleep(100);
//关闭socket
socket.Close();
以上就是SqlServer开启CLR使用(C#)DLL实现实时Socket通知的全文介绍,希望对您学习和使用数据库有所帮助.
这些内容可能对你也有帮助
更多可查看其它数据库列表页。
猜您也会喜欢这些文章Asp.net & C#(204)
MSSQL(55)
--1、默认情况下,SQL Server中的CLR是关闭的,所以我们需要执行如下命令打开CLR:
exec sp_configure 'clr enabled',1
reconfigure
-- 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]
INSERT, DELETE, UPDATE
update触发器会在更新数据后,
将更新前的数据保存在deleted表中,更
新后的数据保存在inserted表中。
DECLARE @UpdateID NVARCHAR(20)
DECLARE @UpdateContent Varchar(MAX)
@UpdateID=(SELECT
Deleted.Id FROM
@UpdateContent=(SELECT
Inserted.UserAddr FROM
dbo.fnScoketSend(@UpdateContent)
INSERT INTO Sample(UserName,UserAddr,AddDate) VALUES('张三','深圳市南山区蛇口',GETDATE())
SELECT * FROM Sample
using Microsoft.SqlServer.S
using System.Collections.G
using System.Data.SqlT
using System.IO;
using System.L
using System.N
using System.Net.S
using System.T
using System.Threading.T
//SqlDependency.dll
namespace SqlDependency
public class Notice
[SqlFunction(IsDeterministic = true, DataAccess = DataAccessKind.Read)]
public static SqlString ScoketSendContent(SqlString Content)
string str = &&;
//创建一个Socket
var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.Connect(&121.77.61.65&, 4530);
System.Threading.Thread.Sleep(100);
var outputBuffer = Encoding.ASCII.GetBytes(&new data&);
socket.BeginSend(outputBuffer, 0, outputBuffer.Length, SocketFlags.None, null, null);
str = &传送成功&;
catch (Exception e)
str = &传送失败& + e.M
if (socket != null && socket.Connected)
//关闭双方通信
socket.Shutdown(SocketShutdown.Both);
System.Threading.Thread.Sleep(100);
//关闭socket
socket.Close();博客访问: 66683
博文数量: 46
博客积分: 0
博客等级: 民兵
技术积分: 462
注册时间:
认证徽章:
IT168企业级官微
微信号:IT168qiye
系统架构师大会
微信号:SACC2013
发布时间: 10:52:21
解决方法:查询分析器中运行如下代码即可:exec sp_configure 'show advanced options', '1';goexec sp_configure 'clr enabled', '1'exec sp_configure 'show advanced options', '1';go转载链接: http://www.cnblogs.com/chu888c.........
阅读(276) | 评论(0) | 转发(0)
发布时间: 17:39:35
摘要: 本文主要讨论了网络负载平衡集群系统下,基本的平衡算法和动态负载平衡机制。在LVS的基础上配合轮询算法实现了集群的动态负反馈机制,给出了一个基本的动态平衡模型并加以分析。1.引言&本质上讲,网络负载平衡是分布式作业调度系统的一种实现。平衡器作为网络请求分配的控制者,要根据集群节点的当前处理能.........
阅读(117) | 评论(0) | 转发(0)
给主人留下些什么吧!~~
请登录后留言。SqlServer/Access(61)
在数据库中运行如下代码即可。
exec sp_configure 'show advanced options', '1';
exec sp_configure 'clr enabled', '1'
exec sp_configure 'show advanced options', '1';}

我要回帖

更多关于 sql clr 启用事务 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信