如何通过MVC中的sored过程字符串查询实时监控更新数据?

时间:2015-06-07 07:55:01

标签: c# sql signalr sqldependency

我可以使用哪些方法实时监控更新数据? 从以下存储过程返回的数据写为字符串查询:

BEGIN TRAN

USE [MyDataBase]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER procedure [dbo].[MySp]
(    
    @UserId INT
)
as
BEGIN

CREATE TABLE #tmp (T1 INT,T2 NVARCHAR(500))
declare @sql nvarchar(max)
SET @sql='select  [T1], [dbo].[MyFunction]('+ cast(@UserId as nvarchar(20))+',[T1],0) as [T2]
          from [dbo].[MyTable]               
          where ( [X] in(50,60) or [Y] in(520,530) ) and  [dbo].[MyFunction]('+ cast(@UserId as nvarchar(20)) +',[T1],0) <>0'

    sp_executesql @sql        
END

编辑1:

过程非字符串查询是:

BEGIN TRAN

USE [MyDataBase]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER procedure [dbo].[MySp]
(    
    @UserId INT
)
as
BEGIN

select  [T1], [dbo].[MyFunction]('+ cast(@UserId as nvarchar(20))+',[T1],0) as [T2]
          from [dbo].[MyTable]               
          where ( [X] in(50,60) or [Y] in(520,530) ) and  [dbo].[MyFunction]('+ cast(@UserId as nvarchar(20)) +',[T1],0) <> 0       
END

但这种方法也不能正常工作。该怎么办?

1 个答案:

答案 0 :(得分:0)

SQLDependency不适用于时态表。

请参阅What are the limitations of SqlDependency