简体   繁体   中英

Image from DB in Reporting Services

Essentially my problem at a basic level is I cannot get my images to display in SSRS. I get the little box with an 'x' in it. These images are being stored in a SQL db from a web app that I've developed and have control over... getting handled by a web service I also have control over.

There are multiple spots I wonder if I have gone wrong:

On the client I use the javascript FileReader API to instantly render a thumbnail of an uploaded image for display to the user. var reader = new FileReader();

After calling reader.readAsDataURL(file); I put the data into a variable imageURL = reader.result and do some string operations to remove data:image/jpeg;base64, from the (base64 encoded) file data string, then eventually pass this variable to the server using a SOAP envelope.

So, on the server the image data is received by my web service (just a .asmx/not WCF) as a string datatype and then eventually inserted into the database as a SQL VARCHAR(MAX).

In reporting services I drop in an image control and set the image source to "database", the field to my photo field from my dataset and the MIME type to jpeg...which is all appropriate I believe.

So... I believe I am doing nothing wrong in SSRS but perhaps I am doing something wrong on the client in terms of how I'm sending the data? OR Perhaps I am choosing to store my image data incorrectly. I do have access to the server machine, so maybe saving the images in the file system is what I need to do, but even still my current method seems like it should work.

Please let me know if I need to provide further information.

To solve your problem you need to change your database field to be either:

  • pre-SQL 2012 - image data type
  • SQL 2012 - varbinary(max) as image data type has been depreciated

You'll also need to change your web service to upload a byte stream rather than a string.

Even if you're using SQL 2008 or 2008R2 I'd recommend you use the varbinary data type for future proofing of your database model.

To create a test data source for an SSRS report use the following SQL to generate a table entitled ImageTest. You'll need to supply the file path to an image which will be uploaded into the table.

CREATE TABLE ImageTest (
  image_data VARBINARY(MAX));

INSERT INTO ImageTest (image_data)
SELECT image_data
FROM OPENROWSET(
        BULK N'<location of an image file>',
        SINGLE_BLOB) AS ImageSource(image_data);

To try out the table in SSRS create a new report with

  • dataset pointing to the table ImageTest
  • add an image control to the report and point its image source to the column image_data

When you preview the report you should see the report using your image stored in the database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM