question

Laura Grimes avatar image
Laura Grimes asked

Issue with fn_cdc_get_all_changes

SQLServer 2008 Instance My client enabled Change Data Capture in lieu of keeping a history of changes in the baseline table. My challenge is that I need to determine if anything changed since the last time I executed.

I have the following logic:

declare @begin_lsn binary(10), @end_lsn binary(10), @prev_run_dt datetime

select @prev_run_dt = getdate() -1 --- example only--getting start date of last successful run

select @begin_lsn = sys.fn.cdc_map_time_to_lsn('smallest greater than', @prev_run_dt)
select @end_lsn = sys.fn_cdc_get_max_lsn()

select * from cdc.fn_cdc_get_all_changes_<change_capture>(@begin_lsn,@end_lsn, N'all')


If there are no changes that have the specific lsn values in my table, the fn_cdc_get_all_changes FAILS..badly..error code 208. According to documentation, you should not query CDC tables directly but use the functions.

Any suggestions on how to get around this?

sql-server-2008change-data-capture
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Matt Whitfield avatar image
Matt Whitfield answered

From MSDN:

If the specified LSN range does not fall within the change tracking timeline for the capture instance, the function returns error 208 ("An insufficient number of arguments were supplied for the procedure or function cdc.fn_cdc_get_all_changes.").

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Laura Grimes avatar image
Laura Grimes answered

Clarification: I guess more specifically, I know why I'm getting the 208 return code but how to I get data from the CDC table when I have a date not a specific lsn for that CDC table?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jason Crider avatar image
Jason Crider answered

I started with the following link: http://technet.microsoft.com/en-us/library/cc645858.aspx

See if that Validating LSN Boundaries section at the top helps you at all.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

TheSmilingDBA avatar image
TheSmilingDBA answered
I changed the begin date to the start of the data in the table and was successful. Thomas
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

TheSmilingDBA avatar image
TheSmilingDBA answered
I changed the begin date to be in the range of the data entered into the table and the error went away. Thomas
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

piers7 avatar image
piers7 answered
Greg Low raised a Connect issue regarding this: http://connect.microsoft.com/SQLServer/feedback/details/303972/cdc-function-error-messages-are-misleading It's closed as won't fix, but if we *all* vote it up... (sorry - this should be a comment on the answer, but I don't have the rep.)
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ThomasRushton avatar image ThomasRushton ♦♦ commented ·
I've voted you up - which helps you on your way to having the rep required! ;-)
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.