What is the most efficient way of reading just part of the binary data from a varbinary(MAX) field (not using FileStreams) in SQL Server 2008?
在SQL Server 2008中,从varbinary(MAX)字段(不使用文件流)读取部分二进制数据的最有效方法是什么?
When writing data to the column the VarBinary.Write() function is available in T-SQL, allowing bytes to be written to the field incrementally, but there doesn't appear to be a similar function available for reading data.
当向列写入数据时,varbin . write()函数在T-SQL中可用,允许将字节递增地写入字段,但似乎没有类似的函数可以用于读取数据。
I know of the DataReader.GetBytes() method in .Net which will select just the bytes you ask for, but does this carry a performance overhead with it? i.e. will the select in sqlserver read all of the bytes in the database, and then give the getBytes() method all of these bytes for it to take the subset of bytes requested from them?
我知道。net中的DataReader.GetBytes()方法,它将只选择您所要求的字节,但是这是否会带来性能开销呢?例如,sqlserver中的select将读取数据库中的所有字节,然后将所有这些字节都给getBytes()方法,让它获取请求的字节的子集吗?
Thanks for any help.
感谢任何帮助。
2 个解决方案
#1
17
You use SUBSTRING. This reads a snippet from your varbinary data on the server, and only returns the snippet to the client.
使用子字符串。这将从服务器上的varbinary数据中读取一个片段,并只将该片段返回给客户机。
#2
1
Using DataReader.GetBytes()
is possible without overhead, afaik. But you'll have to call the ExecuteReader()
with the CommandBehavior.SequentialAccess
option.
使用DataReader.GetBytes()无需开销,afaik是可行的。但是,您必须使用CommandBehavior调用ExecuteReader()。SequentialAccess选项。
#1
17
You use SUBSTRING. This reads a snippet from your varbinary data on the server, and only returns the snippet to the client.
使用子字符串。这将从服务器上的varbinary数据中读取一个片段,并只将该片段返回给客户机。
#2
1
Using DataReader.GetBytes()
is possible without overhead, afaik. But you'll have to call the ExecuteReader()
with the CommandBehavior.SequentialAccess
option.
使用DataReader.GetBytes()无需开销,afaik是可行的。但是,您必须使用CommandBehavior调用ExecuteReader()。SequentialAccess选项。