我有启用“文件流”的数据库。我创建了包含具有“文件流”属性的列的表,并设法成功记录表中的行。所以,我得到的是作为 BLOB 存储在我的“文件流”中的图像。
我的问题是什么?
我必须获取此图像并使用经典 asp 在 Web 浏览器中显示它(我是该服务器语言的新手,并且不允许我使用 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 文件系统的流功能。
那么我真正的问题是什么?
vb.net 代码可以转换并在经典的 asp 中使用吗?如果可以,这是否意味着当我使用“文件流”启用 futures 并希望在 Web 中显示数据时,速度会更慢使用桌面应用程序?
我很困惑,非常感谢任何答案或与要阅读的文章的链接。
I have "File-Stream" enabled database. I have created table with column that has the "file-stream" attribute and manage to record successfully row in the table. So, what I have got is image stored in my "File-Stream" as BLOB.
What is my problem?
I have to get this image and show it in the web browser using classic asp (I am total newbie in this server-language and I am not allowed to use the asp.net). I have searched and read a lot (there are many information about doing that with asp.net and almost nothing showing how to do this with classic asp) and found a article (http://www.simple-talk.com/sql/learn-sql-server/an-introduction-to-sql-server-filestream/) that shows to ways to read the data:
"Accessing FILESTREAM Data using TSQL" and "Accessing FILESTREAM data with Managed API"
The first one I have been able to understand and use. The second one (there is a example with vb.net code) I haven't been able.
This is the code:
‘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()
I was not able to transform this in classic asp but in the same article I have read something more frustrating:
When accessing FILESTREAM data using TSQL, SQL Server reads the content of the >FILESTREAM data file and serves it to the client. SQL Server memory is used for reading >the content of the data file. Accessing FILESTREAM data using Win32 Streaming does not >use SQL Server memory. In addition it allows the application to take advantage of the >Streaming capabilities of the NT File System.
So what is my real problem?
Can be the vb.net code transform and used in a classic asp?And if it can, does that mean that when I am using the "file-stream" enable futures and want to display data in the web it will be more slow then using desktop application?
I am pretty confused and will appreciate any answer or link with article to read.
发布评论
评论(1)
对这个问题有点困惑,但如果您想要做的只是将数据库中的一些 BLOB 数据显示为网页上的图像,那么您应该有一个看起来像这样的“image.asp”页面...
A little confused on the question but if all you're trying to do is display some BLOB data from the database as an Image on the webpage then you should have an "image.asp" page that looks something like this ...