Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What format should the start and end LSN parameters be to sys.fn_dblog?

When I execute

SELECT [Current LSN]
FROM sys.fn_dblog(NULL,NULL)

The LSN values are presented in the format

'000000CB:00000055:0002'

However when I try and pass the start and end LSN parameters explicitly to fn_dblog in that format

SELECT *
FROM   sys.fn_dblog('000000CB:00000055:0002', '000000CC:00000088:000A') 

I get an error, saying...

Msg 9005, Level 16, State 3, Line 1 Either start LSN or end LSN specified in OpenRowset(DBLog, ...) is invalid.

Why doesn't this work and what format do they need to be in?


I did some studies based on this site about LSN and log files... but, or I got an error, or, when I execute the command with the two parameters, I just got 2 rows of informations... I considerate that is intresting, because, when I use a program to read the data-log, I got all the information's.

How I can make to read all the data and informations of log using SQL ?

enter image description here

enter image description here

like image 616
Alexandre Avatar asked Oct 21 '25 01:10

Alexandre


1 Answers

FYI: As of SQL Server 12 (I haven't tested others but as far back as SQL 2000 by the looks), you can add '0x' to the beginning of the LSN text.

SELECT TOP 1 [Current LSN] FROM fn_dblog('0x000000CB:00000055:0002',null)

Obviously if the query returns with no errors and the same LSN in the result then you should be good to go.

Credit to Art of SQL

like image 78
Simon Francesco Avatar answered Oct 22 '25 16:10

Simon Francesco