17.07.2015 Views

The Art of SQL Server FILESTREAM - Red Gate Software

The Art of SQL Server FILESTREAM - Red Gate Software

The Art of SQL Server FILESTREAM - Red Gate Software

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 3: Accessing <strong>FILESTREAM</strong>Data from Client ApplicationsAs discussed in the previous chapters, <strong>FILESTREAM</strong> storage is ideal for BLOB data valuesthat are relatively large (larger than 1 MB). This data can be accessed either throughT-<strong>SQL</strong> code or through the <strong>FILESTREAM</strong> APIs exposed by <strong>SQL</strong> <strong>Server</strong>, though the latteris more efficient than the former.<strong>The</strong> <strong>FILESTREAM</strong> APIs come in two flavors, Win32 and .NET, and in this chapter we'llwalk through several examples using each <strong>of</strong> these I/O streaming APIs.What is Streaming?Streaming, in simple terms, means "continuous flow." Within the context <strong>of</strong> reading andwriting BLOB data, it refers to a continuous flow <strong>of</strong> bytes to and from the physical disk,without local buffering (i.e. without collecting bytes in an intermediate location beforetransmitting the data to the target). Performing <strong>FILESTREAM</strong> operations with streaming<strong>of</strong>fers two immediate benefits. Firstly, it means that only a small memory buffer is needed.Without streaming, potentially large files will be stored in the memory buffer. This couldoverload the server by incurring excessive paging and loss <strong>of</strong> cached execution plans. Itcould also affect other processes running on the server. It is also possible that the file willbe bigger than the available memory on the server.Secondly, streaming gives better performance in several cases. Your process can startsending bytes to the target location even before the entire contents <strong>of</strong> the file are readfrom the source location. This performance benefit may be particularly evident if you areserving the BLOB data to a client over the Internet (such as streaming an audio file ordownloading a file from a client browser).89

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!