web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to read AX 4.0 db image from SSRS 2005/2008

(0) ShareShare
ReportReport
Posted on by 170

Dear all,

I am trying to display images from a SSRS report by reading a Ax 4.0 database without any luck.

search from the forum give me 2 options by using

1. remove first 7 characters from fields Binary. ( substring (image, 7, datalength(image)).

2. follow MSDN http://msdn.microsoft.com/en-us/library/ms156342.aspx by using

=System.Convert.FromBase64String(Mid(System.Convert.ToBase64String(Fields!ImageFieldName.Value),105)) 

** I also try other length because we are using Chinese_taiwan collation.

both seems not working. Does anyone has any sucessful experiences? Thanks in advance.

pan

*This post is locked for comments

I have the same question (0)
  • Luke Shuttlewood Profile Picture
    175 on at

    I guess you looked at this page already if you have been googling:

    forums.devarticles.com/.../displaying-image-fields-in-reporting-services-11844.html

    The guy there has the same problem as you only his is Spanish.  I have never had to use it but he has what appears to be a simple formula to find out the length you'd need for chinese....... with some experimenttation at least.

  • Verified answer
    Brandon Wiese Profile Picture
    17,790 on at

    I have experience retrieving AX 4.0 graphic images from SQL, though I have never used them in a report.

    The encoding of Binary data into an SQL Image field changed during an AX 4.0 Service Pack, and I can no longer remember which one.  So, depending on the AX version in place when the image was saved, the format may vary.

    If you view the SQL Image field using SQL Server Management Studio (for example), the following structure exists for SP2+.

    0x 07 2B L1 L2 L3 L4 FF D8 ..

    In this case, the 2B in the 2nd byte indicates the newer format (SP2+).  Immediately following that are 4 bytes that represent the length (L1-L4 in little endian) of the stored Binary data, starting immediately after that (FF D8 in this case, which is how all JPG files start).  The length represented by L1-L4 will be 7 less than the DATALENGTH(..) of your raw Image field.  I'm not sure if the first byte being 07 is a coincidence or not.

    The other format I have seen looks like this.

    0x XX FD YY L1 L2 L3 L4 FF D8 ..

    In this case, the FD in the 2nd byte indicates the older format.  Skipping one byte, the length is again found as L1-L4, and the Binary data starts one byte later (seen here as FF D8 again, for JPG as an example).

    it appears to me that there's an extra byte at the end of the Binary data that is not actually part of the image.  Perhaps it's a checksum or single byte terminator used by AX, but it does not belong in your graphic Binary data.  For example, in one of my stored images, the DATALENGTH(image) is 8330 or 0x208A, and the data shows 0x83 0x20 0x00 0x00 or 0x2083, a difference of 7. Skipping the first 6 bytes (it started 0x 07 2B so it's the new format), that leaves an extra at the end.

    Be careful of your substring usage.  In .NET, substring is 0 based, meaning that substring(.., 7) in fact skips a full 7 characters (NOT bytes),  Substring("abc", 1, 1) returns "b" not "a".  And if you're using Unicode string variables, then Substring(.., 7) could in fact skip 14 bytes.

    You probably want to skip 6 bytes and start at the 7th position, discarding the last byte.  You can sanity check your code by saving a JPG image for testing and validating during debugging that your Binary result starts with FF D8 and ends with FF D9, since all JPG files start and end this way.  You can also code your logic to check the 2nd byte position for the 2B or FD indicator and adjust the starting position of the Binary data accordingly, in case you have a mixture of old and new Image data.

    Good luck.

  • Verified answer
    pan Profile Picture
    170 on at

    Thanks for the suggestion. I still got no luck after tring your method again.

    substring(l.image, 8, datalength(l.image) -8)  will give the a raw jpeg binary file but it just won't show up in Report Server.

    So what I did is just write a job in Ax and save all images to a nework path using recid and cut the recid in 3 sub-folders. Use the Recid of image table and show it on reports.

    Thanks again for your suggestion.

    pan

  • Luke Shuttlewood Profile Picture
    175 on at

    Hi Pan,

    I have managed to get mine working (abeit my setup/images are english based).  

    Heres the SSRS 2008 expression I used to retrieve images from AX2009:

    =System.Text.Encoding.Default.GetBytes(Mid(System.Text.Encoding.Default.GetString(Fields!Picture.Value),8))

    Let me know what happens.

  • pan Profile Picture
    170 on at

    Hi Luke,

    Thanks for solutions. I'm really appreciated!

    since the thread already more than 2 months ago. I already killed my SSRS 2008 testing server and went for other solution.

    for a quick test, our server is 2005 with AX4.0 SP2 (early version).

    using SQL query substring(l.image, 8, datalength(l.image) -8)  will give half or partial image.

    your code =System.Text.Encoding.Default.GetBytes(Mid(System.Text.Encoding.Default.GetString(Fields!Picture.Value),8)) won't show the image, it maybe because our db is chinese collation... or may be SSRS 2008...

    which i think the solution you guys provided should work as long as the Ax setup is not as same as our company.

    thanks again guys!

  • Luke Shuttlewood Profile Picture
    175 on at

    No problem.

    You may be interested in this page too:

    www.hakasolutions.com/.../Insert-Company-logo-in-SSRS-reports-AX

    I don't think that collation will be the issue. In very very basic terms collation is used to sort data based on language.  eg english goes from A-Z ( I don't know any Chinese to give an example!).

    Check out:

    msdn.microsoft.com/.../ms144260.aspx

    msdn.microsoft.com/.../aa174903(v=sql.80).aspx

    My point here is that the IMAGE data type is just BINARY.  You'd (probably) never sort on a binary field and binary isn't language specific therefore SQL won't alter it in anyway when you call it.

    To back that up, a third link from MS quotes:

    "Data in an image data is stored as a string of bits and is not interpreted by SQL Server. Any interpretation of the data in an image column must be made by the application. For example, an application could store data in an image column using a BMP, TIFF, GIF, or JPEG format. The application that reads the data from the image column must recognize the format of the data and display it correctly. All an image column does is provide a location to store the stream of bits that make up the image data value."

    Here is the link: msdn.microsoft.com/.../aa224006(v=sql.80).aspx

    I have never used SSRS 2005 which is what you are using, right?  Not that that should make any difference.  What picture format are you trying to retrieve? BMP / JPEG / PNG??

  • Community Member Profile Picture
    on at

    Hi, pan.

    I wonder whether it can be accomplished by building an image viewer to help read and display images from a SSRS report? I am learning about how to build web image viewer with the help of some manual tools which can be customized by users according to our own favors to help view and display images these days. You can also google it and select a professional 3rd party image processor whose way of processing is simple and fast to help you with the related work. Remember to check its free trial package first if possible. I hope you success. Good luck.



    Best regards,
    Arron

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 26

#2
imran ul haq Profile Picture

imran ul haq 8

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 4 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans