【问题标题】:Accessing File-Stream Data Methods (T-SQL and Managed API)访问文件流数据方法(T-SQL 和托管 API)
【发布时间】:2011-12-29 20:29:40
【问题描述】:

我有启用“文件流”的数据库。我已经创建了具有“文件流”属性的列的表,并设法在表中成功记录行。所以,我得到的是作为 BLOB 存储在“文件流”中的图像。

我的问题是什么?

我必须得到这张图片并使用经典的 asp 在网络浏览器中显示它(我完全是这种服务器语言的新手,我不允许使用 asp.net)。我已经搜索并阅读了很多(有很多关于使用 asp.net 执行此操作的信息,几乎没有任何内容显示如何使用经典 asp 执行此操作)并找到了一篇文章 (http://www.simple-talk.com/sql/learn-sql-server/an-introduction-to-sql-server-filestream/),其中显示了读取数据的方法:

“使用 TSQL 访问 FILESTREAM 数据”和“使用托管 API 访问 FILESTREAM 数据”

我已经能够理解和使用的第一个。第二个(有vb.net代码的例子)我没弄过。

这是代码:

‘Create a connection to the database

Dim ConStr As String

ConStr = "Data Source=JACOBXPS\katmaifs;Initial Catalog=NorthPole" & _

     ";Integrated Security=True"

Dim con As New SqlConnection(ConStr)

con.Open()



'Retrieve the FilePath() of the image file

Dim sqlCommand As New SqlCommand()

sqlCommand.Connection = con

sqlCommand.CommandText = "SELECT ItemImage.PathName() AS PathName " + _

                     "FROM items WHERE ItemNumber = 'MS1001'"

Dim filePath As String = sqlCommand.ExecuteScalar()



'Obtain a Transaction Context

Dim transaction As SqlTransaction = con.BeginTransaction("ItemTran")

sqlCommand.Transaction = transaction

sqlCommand.CommandText = "SELECT GET_FILESTREAM_TRANSACTION_CONTEXT()"

Dim txContext As Byte() = sqlCommand.ExecuteScalar()



' Open and read file using SqlFileStream Class

Dim sqlFileStream As New SqlFileStream(filePath, txContext, FileAccess.Read)

Dim buffer As Byte() = New Byte(sqlFileStream.Length) {}

sqlFileStream.Read(buffer, 0, buffer.Length)



'Bind the image data to an image control

Dim ms As MemoryStream = New MemoryStream(buffer)

Dim bmp As Bitmap = New Bitmap(ms)

ItemImage.Image = bmp



'Cleanup

sqlFileStream.Close()

sqlCommand.Transaction.Commit()

con.Close()

我无法在经典的 asp 中对此进行转换,但在同一篇文章中我读到了更令人沮丧的内容:

当使用 TSQL 访问 FILESTREAM 数据时,SQL Server 读取 >FILESTREAM 数据文件的内容并将其提供给客户端。 SQL Server 内存用于读取数据文件的内容。使用 Win32 Streaming 访问 FILESTREAM 数据不会>使用 SQL Server 内存。此外,它还允许应用程序利用 NT 文件系统的 >Streaming 功能。

那么我真正的问题是什么?

可以是 vb.net 代码转换并在经典 asp 中使用吗?如果可以,这是否意味着当我使用“文件流”启用期货并希望在网络中显示数据时比使用桌面应用程序更慢?

我很困惑,如果有任何答案或文章链接,我将不胜感激。

【问题讨论】:

    标签: tsql methods asp-classic filestream


    【解决方案1】:

    对这个问题有点困惑,但如果您只想将数据库中的一些 BLOB 数据显示为网页上的图像,那么您应该有一个看起来像这样的“image.asp”页面.. .

    SQL = "SELECT FILE_NAME,IMAGE_FILE FROM tblImages WHERE ID = " & request("id")
    Set rs =db.Execute( SQL )
    if not(rs.eof) then
    
        Response.ContentType = "application/octet-stream"
        Response.AddHeader "Content-Disposition", "attachment;filename=" & rs("FILE_NAME")
        Response.BinaryWrite rs("IMAGE_FILE")
    else
        response.Write("No such record found in the database at row " & request("id"))
    end if
    

    【讨论】:

      猜你喜欢
      • 2019-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-02
      • 1970-01-01
      • 1970-01-01
      • 2018-03-18
      相关资源
      最近更新 更多