【发布时间】: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