gpt4 book ai didi

sql-server - 更改数据捕获错误

转载 作者:行者123 更新时间:2023-12-03 00:46:55 25 4
gpt4 key购买 nike

我试图通过传递最小和最大日期来获取启用 CDC 的表上的净更改。但抛出以下错误。

Msg 313, Level 16, State 3, Line 24
An insufficient number of arguments were supplied for the procedure or function cdc.fn_cdc_get_net_changes_ ... .

我的代码如下:

DECLARE @CDate DATE = '2013-03-18' --This is the date after the CDC was enabled on the table
DECLARE @count INT;
DECLARE @lsnStartDatetime DATETIME;
DECLARE @lsnEndDateTime DATETIME;

DECLARE @begin_time DATETIME ,
@end_time DATETIME ,
@from_lsn BINARY(10) ,
@to_lsn BINARY(10);


SELECT @lsnStartDatetime = CAST(CAST(@CDate AS NVARCHAR(10)) + ' 00:00:00' AS DATETIME)
SELECT @lsnEndDateTime = CAST(CAST(@CDate AS NVARCHAR(10)) + ' 23:59:59' AS DATETIME)


SET @from_lsn = sys.fn_cdc_map_time_to_lsn('smallest greater than or equal',
@lsnStartDatetime);
SET @to_lsn = sys.fn_cdc_map_time_to_lsn('largest less than or equal',
@lsnEndDateTime);

if exists (select * from sys.objects where name = 'EmployeeCDCbyDate' and type = 'u')
drop table etl.EmployeeCDCbyDate
SELECT *
FROM cdc.fn_cdc_get_net_changes_employee(@from_lsn, @to_lsn, N'all')

从 sys.fn_cdc_map_time_to_lsn 获取的 from_lsn 和 to_lsn 是否与映射到 cdc 表“employee”不匹配

下面的代码工作正常;但它从 min max lsn 获取所有净变化。

DECLARE @min_lsn BINARY(10) = sys.fn_cdc_get_min_lsn ('employee')
DECLARE @max_lsn BINARY(10) = sys.fn_cdc_get_max_lsn ()
SELECT * FROM cdc.fn_cdc_get_net_changes_employee(@min_lsn, @max_lsn, 'all') ORDER BY 1 desc

我需要的是获取给定日期的 cdc 实例的最小和最大 lsn,并获取该日期的净更改。有什么线索吗?

编辑:

当我在一堆表上启用时,这对第一个表来说效果很好。

例如:

USE ERP

EXEC sys.sp_cdc_disable_db
EXEC sys.sp_cdc_enable_db

EXEC sys.sp_cdc_enable_table @source_schema = N'dbo',
@source_name = N'Employee',
@capture_instance = 'Employee',
@supports_net_changes =1,
@role_name = NULL

EXEC sys.sp_cdc_enable_table @source_schema = N'dbo',
@source_name = N'StoreListing',
@capture_instance = 'StoreListing',
@supports_net_changes =1,
@role_name = NULL

Go

这适用于 Employee 表。如果我更改它们启用 CDC 的顺序(如果我将商店列表放在前面,然后将员工放在后面),那么它可以很好地处理员工列表。

最佳答案

MSDN Social 上有类似问题的答案:Is there bug with cdc.fn_cdc_get_net_changes_.... in SQL Server 2012 .

它被标记为由主持人回答。引用如下:

I tested in my server. When I ran the script in the SQL Server 2008 R2, it could be run successfully without error.

When I ran the script in SQL Server 2012, the error message came out the same as yours. I think you could try to apply the latest SQL Server 2012 Service Pack to see if it would OK.

And here is a bug report with Microsoft.正在调查中。

关于sql-server - 更改数据捕获错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15513808/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com