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?

more ▼

asked Jan 15 '10 at 04:41 PM in Default

Laura Grimes gravatar image

Laura Grimes
22 1 1 1

(comments are locked)
10|1200 characters needed characters left

6 answers: sort voted first

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.").

more ▼

answered Jan 16 '10 at 10:31 AM

Matt Whitfield gravatar image

Matt Whitfield ♦♦
29.4k 61 65 87

(comments are locked)
10|1200 characters needed characters left

I changed the begin date to the start of the data in the table and was successful.

more ▼

answered Mar 05 '12 at 10:27 PM

TheSmilingDBA gravatar image

91 1 1 2

(comments are locked)
10|1200 characters needed characters left

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.)
more ▼

answered Mar 28 '13 at 04:54 AM

piers7 gravatar image


I've voted you up - which helps you on your way to having the rep required! ;-)
Mar 28 '13 at 09:22 AM ThomasRushton ♦
(comments are locked)
10|1200 characters needed characters left

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?

more ▼

answered Jan 18 '10 at 01:44 PM

Laura Grimes gravatar image

Laura Grimes
22 1 1 1

(comments are locked)
10|1200 characters needed characters left

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.

more ▼

answered May 07 '10 at 10:32 AM

Jason Crider gravatar image

Jason Crider
453 10 10 12

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.



asked: Jan 15 '10 at 04:41 PM

Seen: 3989 times

Last Updated: Mar 28 '13 at 09:22 AM