Skip to content

Relog.exe imports a CounterDateTime data incorrectly (likely a bug): we can work around it by updating the data manually in post-import logic #150

@PiJoCoder

Description

@PiJoCoder

This is an issue with Relog.exe. So we have to work around it.

Repro Steps:

  1. Import a .BLG file in a database

    C:\Windows\System32>relog "c:\temp\sqldiag.blg" -f sql -o "SQL:sqldefaultinstance!TestRelog"
    Input
    ----------------
    File(s):
         c:\temp\SQLDIAG.BLG (Binary)
    
    Begin:    6/3/2020 16:18:18
    End:      6/3/2020 16:19:29
    Samples:  15
    
    100.00%
    
    
    Output
    ----------------
    File:     SQL:sqldefaultinstance!TestRelog
    
    Begin:    6/3/2020 16:18:18
    End:      6/3/2020 16:19:29
    Samples:  15
    
    The command completed successfully.
    
  2. Connect to the database server and run the following queries

    SELECT TOP (5) 
          [CounterDateTime]
          ,[CounterValue]
          ,[FirstValueA]
          ,[FirstValueB]
          ,[SecondValueA]
          ,[SecondValueB]
      FROM [TestRelog].[dbo].[CounterData]

    Result:

    CounterDateTime          CounterValue           FirstValueA FirstValueB SecondValueA SecondValueB
    ------------------------ ---------------------- ----------- ----------- ------------ ------------
    2020-06-03 16:18:18.970  0                      0           0           789406234    246
    2020-06-03 16:18:24.016  0                      0           0           839873505    246
    2020-06-03 16:18:29.065  0                      0           0           890361981    246
    2020-06-03 16:18:34.116  0                      0           0           940875170    246
    2020-06-03 16:18:39.163  0                      0           0           991350448    246
    
    (5 rows affected)
    
  3. Take a value from above output and try to search for it. THE QUERY RETURNS NO RESULTS BECAUSE THE DATA IS INVALID

 select top (5) CounterDateTime 
 from counterdata
 where CounterDateTime = '2020-06-03 16:18:18.970'
 go
 Result: 
 
 CounterDateTime
 ------------------------
 
 (0 rows affected)
  1. Attempt conversion - CONVERSION TO DATETIME FAILS BECAUSE THE DATA IS INVALID DateTime

    select cast(CounterDateTime as datetime)
    from counterdata
    go
    Result: 
    
    -----------------------
    Msg 241, Level 16, State 1, Line 15
    Conversion failed when converting date and/or time from character string.
    
  2. Analysis shows that the last character is null/0 and should be 0x20

    select top (5)
    ASCII(substring(CounterDateTime,24,1)) LastCharacter
    ,CounterDateTime
    from counterdata
    Result: 
    
    LastCharacter CounterDateTime
    ------------- ------------------------
    0             2020-06-03 16:18:18.970 
    0             2020-06-03 16:18:24.016 
    0             2020-06-03 16:18:29.065 
    0             2020-06-03 16:18:34.116 
    0             2020-06-03 16:18:39.163 
    
    (5 rows affected)
    
  3. Manual fix (workaround) which shows the root cause. Fix the data by running this update.

    --update the last character to 0x20
    update counterdata set CounterDateTime = 
    substring(CounterDateTime, 1,23) + char(32) 
    from counterdata
  4. Now queries work

    select top (5) CounterDateTime 
    from counterdata
    where CounterDateTime = '2020-06-03 16:18:18.970'
    go
    CounterDateTime
    ------------------------
    2020-06-03 16:18:18.970 
    2020-06-03 16:18:18.970 
    2020-06-03 16:18:18.970 
    2020-06-03 16:18:18.970 
    2020-06-03 16:18:18.970 
    
    (5 rows affected)
    
    select cast(CounterDateTime as datetime)
    from counterdata
    go
    -----------------------
    2020-06-03 16:18:18.970
    2020-06-03 16:18:24.017
    2020-06-03 16:18:29.067
    2020-06-03 16:18:34.117
    2020-06-03 16:18:39.163
    2020-06-03 16:18:44.213
    

Metadata

Metadata

Labels

bugwave 1 - completeconsider this issue for next wave of fixeswave 2 - completeconsider this issue for next wave of fixes

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions