简体   繁体   English

来自Reporting Services中数据库的图像

[英]Image from DB in Reporting Services

Essentially my problem at a basic level is I cannot get my images to display in SSRS. 从本质上讲,我的基本问题是我无法在SSRS中显示图像。 I get the little box with an 'x' in it. 我得到了一个带有“ x”的小盒子。 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. 这些图像我开发并控制的Web应用程序存储在SQL db中 ...由Web服务处理,我也可以控制。

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. 在客户端上,我使用javascript FileReader API即时呈现上载图像的缩略图以显示给用户。 var reader = new FileReader();

After calling reader.readAsDataURL(file); 调用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. 我将数据放入变量imageURL = reader.result并进行了一些字符串操作以从(base64编码的)文件数据字符串中删除data:image/jpeg;base64, ,然后最终使用SOAP信封将此变量传递给服务器。

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). 因此, 在服务器上 ,图像数据由我的Web服务(只是.asmx /不是WCF)作为字符串数据类型接收,然后最终作为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. 报表服务中,我放入一个图像控件,然后将图像源设置为“数据库”,将字段从我的数据集中设置为我的照片字段,并将MIME类型设置为jpeg ...我相信这都是适当的。

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? 所以...我相信我在SSRS中没有做错任何事情,但是也许在客户端上我在如何发送数据方面做错了什么? 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之前的版本-图像数据类型
  • SQL 2012 - varbinary(max) as image data type has been depreciated SQL 2012-varbinary(max)作为图像数据类型已弃用

You'll also need to change your web service to upload a byte stream rather than a string. 您还需要更改Web服务以上传字节流而不是字符串。

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. 即使您使用的是SQL 2008或2008R2,我也建议您使用varbinary数据类型来将来对数据库模型进行打样。

To create a test data source for an SSRS report use the following SQL to generate a table entitled ImageTest. 要为SSRS报告创建测试数据源,请使用以下SQL生成名为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 要尝试在SSRS中创建表格,请使用

  • dataset pointing to the table ImageTest 指向表ImageTest的数据集
  • add an image control to the report and point its image source to the column image_data 向报表添加图像控件,并将其图像源指向image_data列

When you preview the report you should see the report using your image stored in the database. 预览报告时,您应该使用存储在数据库中的图像来查看报告。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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