【问题标题】:How to store image blob data in SQL Server 2008?如何在 SQL Server 2008 中存储图像 blob 数据?
【发布时间】:2015-04-02 18:46:51
【问题描述】:

我需要将图像 blob 数据存储在表中。我知道在数据库表中以 blob 格式存储图像不是最佳做法。但这样做是客户的要求。我正在使用 ColdFusion 10 和 SQL Server 2008。我已经使用这个 sn-p 在 SQL server 中插入图像 blob 数据。

<cfimage action="read" name="imdata" source="C:\inetpub\wwwroot\a.jpg" >

<cfquery datasource="localdsn">
  INSERT INTO imtbl(image)
  VALUES #imageGetBlob(imdata)#
</cfquery>

但它正在抛出错误

ByteArray objects cannot be converted to strings.

我也尝试过使用#toString(imageGetBlob(imdata))# 仍然没有成功。

我已经通过https://forums.adobe.com/thread/60629但是找不到任何解决方案。

【问题讨论】:

  • 您是否在 ColdFusion 数据源上启用了 BLOB 设置?
  • 您是否尝试过使用 cfqueryparam 参数化博客?像&lt;cfqueryparam cfsqltype="cf_sql_blob" value="#imageGetBlob(imdata)#"&gt; 这样的东西可能有助于揭露正在发生的事情。
  • @Miguel-F:是的,我已启用它,但仍然无法正常工作,
  • 差不多。 FileReadBinary() 需要一个文件路径。您正在传递一个图像变量。去掉cfimage 并在你的cfqueryparam 中使用FileReadBinary("C:\inetpub\wwwroot\a.jpg")。此外,您显然需要在 VALUES (...) 子句中加上括号。
  • 我会添加以下通知:如果您在SQL Server中使用图像类型(将在以后的版本中删除),请将其替换为varbinary(max) - VarBinary vs Image SQL Server数据类型存储二进制数据?

标签: sql-server sql-server-2008 coldfusion coldfusion-10


【解决方案1】:

我终于解决了这个问题。我做了两件事,

  1. 我已为数据源启用 BLOB 设置。

  2. 我终于用上了这个查询

<cfquery datasource="localdsn"> INSERT INTO imtbl(image) VALUES ( <cfqueryparam cfsqltype="cf_sql_blob" value="#fileReadBinary('C:\inetpub\wwwroot\a.jpg')#"> ) </cfquery>

【讨论】:

    猜你喜欢
    • 2015-08-08
    • 2019-10-06
    • 2017-04-28
    • 1970-01-01
    • 2012-11-18
    • 2015-02-05
    • 2014-07-16
    • 2011-01-25
    • 2011-08-02
    相关资源
    最近更新 更多