相关疑难解决方法(0)

如何从SQL Server内存中清除SqlDependency?

如何清理SQL Server以清除过期的SqlDependency对象?从SqlDepedency对象收到事件后,我需要创建一个新事件才能获得新事件.但是,SQL Server进程的内存使用量会增加,直到超出允许的内存(SQL Server Express).如何摆脱旧查询?

码:

// Func: RegisterTableListener
using (SqlConnection cn = new SqlConnection(Properties.Settings.Default.DatabseEventConnectionString))
{
if (cmd == null)
{
    cmd = cn.CreateCommand();

    cmd.CommandType = CommandType.Text;
    cmd.CommandText = "SELECT HostName, LastStatus, LastDetails, xml FROM dbo.[SystemTable]";
}

lock (cmd)
{
    cmd.Connection = cn;
    cn.Open();
    cmd.Notification = null;

    //  creates a new dependency for the SqlCommand
    if (dep == null)
        dep = new SqlDependency(cmd);
    //  creates an event handler for the notification of data
    //      changes in …
Run Code Online (Sandbox Code Playgroud)

c# sql sql-server-2008 sqldependency

12
推荐指数
1
解决办法
5266
查看次数

当新记录插入到DB时触发Windows服务

可能重复:
使用Sql Server 2008更改通知

我只是想知道无论如何我可以在C#中编写一个Windows服务,当新记录插入数据库时​​将触发该服务.

我想通过wcf连接DB.请提出任何想法或建议.

提前致谢.

基于demo.b指令,这是代码.

SQL数据库细节


我的数据库名称:MyWeb,表名称:StoryItems,列:位置,标题,名称,类型.


 public partial class Triggers
{
    // Enter existing table or view for the target and uncomment the attribute line
    [Microsoft.SqlServer.Server.SqlTrigger(Name = "Trigger_Web", Target = "StoryItems", Event = "FOR INSERT")]
    public static void Trigger_Web()
    {

    SqlCommand command;
    SqlTriggerContext triggerContext = SqlContext.TriggerContext;
    SqlPipe pipe = SqlContext.Pipe;
    SqlDataReader reader;

    if (triggerContext.TriggerAction == TriggerAction.Insert)
    {
        using (SqlConnection connection = new SqlConnection(@"context connection=true"))
        {
            connection.Open();
            command = new SqlCommand(@"SELECT * FROM StoryItems", connection);
            reader = …
Run Code Online (Sandbox Code Playgroud)

c#

7
推荐指数
1
解决办法
1万
查看次数

如何侦听SQL Server数据库更改

使用.Net 4.0和SQL Server 2008 R2

我一直在寻求利用SqlDependency/SqlNotifications来监控一些数据库结构.这是将SqlDependency/SqlNotifications与SQL Server Service代理一起使用的最佳过程/实践吗?

人们是否使用其他方法来完成类似的任务?我总是可以查看更改,但我宁愿不必这样做.另一方面,我也不想在我们现有的环境中引入复杂的场景.

编辑(潜在选项):

  1. 的SqlDependency
  2. Service Broker外部激活

c# sql-server sql-server-2008-r2

7
推荐指数
1
解决办法
4908
查看次数

更新数据库时通知我的WCF服务

我有一个WCF服务,当数据库发生更改时需要通知它的客户端(sql server 2005).只要我找到一种方法来通知我的服务任何更改,这相对容易完成.我可以在表上创建一个数据库触发器并让该触发器启动一个通知我的服务的小服务客户端,但我想知道是否有更好的方法来执行此操作?让服务轮询数据库进行更改是一个可行的解决方案,但我不确定最好的方法(并向我的服务发送通知将是首选).

由于相关更新仅适用于数据库的某个部分,我还想知道是否也可以将这样的触发器(或其他机制)链接到数据库图表.

所有帮助表示赞赏!rinze

sql wcf notifications triggers sql-server-2005

6
推荐指数
1
解决办法
5952
查看次数

数据库更改通知到Windows服务?

WebAPI用来将一些数据推送到数据库.

在同一服务器中运行的Windows服务必须在数据插入时得到通知 WebAPI

我已经看到这个问题建议使用Service Broker或者SqlDependency问题似乎是在不久前提出来的.

我google了但找不到更简单的解决方案.我想做的就是when a new data is inserted to Database, a function in the the windows service should fire.

我们在WebAPI - Windows Services上下文中是否有任何替代方案或类似的解决方案?

.net c# sql-server windows-services asp.net-web-api

5
推荐指数
1
解决办法
641
查看次数