是否有类似 SqlFileStream 的类可与 Sql Server 2005 一起使用?

发布于 2024-08-18 23:39:43 字数 853 浏览 1 评论 0 原文

对于这个问题的背景, 请参阅“如何序列化大型 .NET 对象到 SQL Server 的图表 无需创建大的 BLOB 缓冲区?” 现在有一个很大的 赏金。

SqlFileStream 为您提供IoStream 位于 blob 顶部 (varbinary) 存储在数据库中的值。然而,由于 SqlFileStream 实现的限制,它只能与 Sql Server 2008 一起使用。

从逻辑上讲,我看不出为什么不能在 Sql Server 2000 和 Sql Server 2005 上提供某些 API 的任何原因。

  • 有谁知道这是否已完成?
  • 任何地方都有这个开源实现吗?
  • 我认为这应该是可能的,我错过了什么?

For the background to this question,
see “How to I serialize a large
graph of .NET object into a SQL Server
BLOB without creating a large
buffer?”
that now has a large
bounty on it.

SqlFileStream gives you an IoStream that sits on top of a blob (varbinary) value that is stored in the database. However due to limitations on SqlFileStream implementation it will only work with Sql Server 2008.

Logically I can’t see any reason why the some API cannot be provided on Sql Server 2000 and Sql Server 2005.

  • Does anyone know if this has been done?
  • Is there an open source implementation of this anywhere?
  • What am I missing in thinking it should be possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

饮惑 2024-08-25 23:39:43

我不知道 SqlFileStream SQL Server 2008 以外的任何类。我怀疑这完全是因为 SqlFileStream 类专门设计为“位于”FILESTREAM 类型的列之上SQL Server 2008 中。

FILESTREAM 列/数据类型< /a> 仅在 SQL Server 2008 中可用,本质上允许在此列中存储大量数据。 FILESTREAM 列实际上是带有 FILESTREAM 修饰符的 varbinary(max) 列。这本质上会导致 SQL Server 有效地绕过 RDBMS 存储子系统,并将二进制数据直接存储在底层 NTFS 文件系统上,同时从 RDBMS 角度保持该数据的事务完整性。

MSDN 文章这样指出:

指定 FILESTREAM 属性
varbinary(max) 列会导致 SQL
服务器将数据存储在本地
NTFS 文件系统而不是
数据库文件。 Transact-SQL 语句
提供数据操作能力
服务器内和 Win32 文件
系统接口提供流
访问数据。

SQL Server 2008 中的 FILESTREAM 数据 MSDN 文章还指出:

SqlFileStream API 工作在
SQL Server 事务的上下文。

但还有一点:

SqlFileStream继承自
System.IO.Stream类,它提供
读取和写入的方法
数据流。从流中读取
将数据从流传输到
数据结构,例如数组
字节。写入传输的数据来自
将数据结构转换为流。

建议在内部,SqlFileStream 以与“bog-standard”相同的方式运行 FileStream class

但是,也许最能说明问题的细节是为什么此功能在早期版本的 SQL Server 中不可用(未实现任何类型的 FILESTREAM 或“ direct-to-underlying-storage”列类型)来自 FILESTREAM 概述 MSDN 文章指出:

FILESTREAM 集成了 SQL Server
具有 NTFS 文件的数据库引擎
系统通过存储 varbinary(max)
二进制大对象 (BLOB) 数据为
文件系统上的文件。事务处理SQL
语句可以插入、更新、查询、
搜索和备份 FILESTREAM 数据。
Win32文件系统接口提供
对数据的流式访问。

FILESTREAM 使用 NT 系统缓存来缓存文件数据。这有帮助
减少 FILESTREAM 数据的任何影响
数据库引擎上可能有
表现。 SQL Server 缓冲区
未使用池;因此,这个
内存可供查询
处理。

这本质上是说,使用 SqlFileStream 对象的行为几乎与“标准”FileStream 对象相同,除了 SQL Server(出于事务完整性目的)将充当一个非常轻量级的“看门人”(或“包装器”)来读写由于以前版本的 SQL Server 没有提供此类功能以及与底层 NTFS 文件系统的直接集成,因此我认为不可能针对任何版本的 SQL 实现 SqlFileStream。 SQL Server 2008 之前的服务器。(至少没有一个具有相同的“写入文件,但维护 RDBMS 事务完整性”功能)。

I don't know of a SqlFileStream class for anything other than SQL Server 2008. I suspect this is entirely down the fact that the SqlFileStream class is specifically designed to "sit on top of" a column of type FILESTREAM within SQL Server 2008.

The FILESTREAM column/datatype is only available in SQL Server 2008 and essentially allows large volumes of data to be stored in this column. A FILESTREAM column is actually a varbinary(max) column with a FILESTREAM modifier. This essentially causes the SQL Server to effectively bypass the RDBMS storage sub-system and store the binary data directly on the underlying NTFS file system, whist maintaining transactional integrity for this data from the RDBMS perspective.

The MSDN article states this thusly:

Specifying the FILESTREAM attribute on
a varbinary(max) column causes SQL
Server to store the data in the local
NTFS file system instead of in the
database file. Transact-SQL statements
provide data manipulation capabilities
within the server, and Win32 file
system interfaces provide streaming
access to the data.

The FILESTREAM Data in SQL Server 2008 MSDN article also states that:

The SqlFileStream API works in the
context of a SQL Server transaction.

But also that:

SqlFileStream inherits from the
System.IO.Stream class, which provides
methods for reading and writing to
streams of data. Reading from a stream
transfers data from the stream into a
data structure, such as an array of
bytes. Writing transfers the data from
the data structure into a stream.

Suggesting that, internally, the SqlFileStream operates in the same manner as a "bog-standard" FileStream class

However, perhaps the most telling details as to why this functionality is not available in prior versions of SQL Server (that do not implement any type of FILESTREAM or "direct-to-underlying-storage" column type) is from the FILESTREAM Overview MSDN article that states:

FILESTREAM integrates the SQL Server
Database Engine with an NTFS file
system by storing varbinary(max)
binary large object (BLOB) data as
files on the file system. Transact-SQL
statements can insert, update, query,
search, and back up FILESTREAM data.
Win32 file system interfaces provide
streaming access to the data.

FILESTREAM uses the NT system cache for caching file data. This helps
reduce any effect that FILESTREAM data
might have on Database Engine
performance. The SQL Server buffer
pool is not used; therefore, this
memory is available for query
processing.

This essentially says that using a SqlFileStream object will act almost identically to a "standard" FileStream object, except that SQL Server (for transactional integrity purposes) will act as a very lightweight "gatekeeper" (or "wrapper) for your reading and writing of binary data to an underlying NTFS file system file. Since no previous version of SQL Server has offered such functionality and direct integration with the underlying NTFS file system, I'd say that it would not be possible to implement a SqlFileStream against any version of SQL Server prior to SQL Server 2008. (At least not one that has the same "write to a file, but maintain RDBMS transactional integrity" features).

梨涡少年 2024-08-25 23:39:43

FILESTREAM 数据类型是在 SQL Server 2008 中引入的,在 SQL Server 2005 中没有等效数据类型。此数据类型的处理方式与“普通”blob 类型不同。 FILESTREAM 数据作为文件单独保存在数据库中,而 blob(文本或 varchar(max) 等)则直接保存在数据页内。因此,您可以在 SQL 2008 中使用 SqlFileStream 流式传输文件内容,但要读取 blob,数据库引擎必须将它们加载到服务器内存中并作为整体返回给客户端。因此,不可能将 SqlFileStream 等任何内容直接附加到 SQL 2005 中的 blob 列。

The FILESTREAM datatype was introduced in SQL Server 2008 and there is no equivalent in SQL Server 2005. This datatype is handled differently than a 'normal' blob type. FILESTREAM data are kept separately to the database as files, while blobs (text or varchar(max) and alike) are kept directly within data pages. So, you can stream contents of files with SqlFileStream in SQL 2008, but to read blobs, db engine has to load them into server memory and return to client as a whole. Because of that it is not possible to have anything like SqlFileStream attached directly to a blob column in SQL 2005.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文