Read Dynamics NAV Table Metadata with SQL

前端 未结 3 552
南方客
南方客 2020-12-10 08:26

I would like to be able to read the Dynamics NAV 2013 Table Metadata directly from the SQL Server database without requiring the NAV Development Environment.

I can v

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-10 08:58

    I was able to get an answer for the format of these Metadata binary fields from the author of the deV.ch - man vs. code, Dynamics NAV & C# .NET blog. Based on the reverse engineering by devch, we determined that the first four bytes (32 bits) of these fields are used by NAV to store a "magic number" that determines the custom NAV Blob type.

    In the case of these metadata fields, the NAV Compressed Blob-Type magic number is 0x02457d5b (hex). In order to use the standard .Net DeflateStream to Decompress, just throw away those first four magic-number bytes and then process the rest of the stream with DeflateStream as usual.

    I was able to successfully test this process with .Net, now I plan to test with Python or some other non-Microsoft deflate tools to see if the deflate implementation follows the industry standard. Thanks again to devch for the article that led to this solution: Accessing Compressed Blobs from outside NAV (NAV2013) (Revisited).

    Update: tested with Python zlib and it works! Standards-compliant Deflate algorithm is used once the custom NAV Blob-type magic number is removed. Here's some sample code (Python):

    # Example Using Python 3.x
    import zlib, sys, struct
    
    # NAV custom Blob-Type identifier (first 4 bytes)
    magic = struct.unpack('>I',sys.stdin.buffer.read(4))[0]
    print('magic number = %#010x' % magic, file=sys.stderr)
    # Remaining binary data is standard DEFLATE without header
    input = sys.stdin.buffer.read()
    output = zlib.decompress(input,-15)
    sys.stdout.buffer.write(output)
    

    Use something like the following to test:

    python -u test.py < Input_Meta.blob > Output_Meta.txt
    

    Of course the .Net DeflateStream works after removing the first four bytes as well. This example is just to show that you're not limited to using .Net languages.

提交回复
热议问题