Friday, January 29, 2010

FILESTREAM in SQL Server 2008

In SQL Server many times our data type is not limited to only string and numbers. We need to store a large amount of data like documents, photos etc. in SQL Server table. SQL Server provides special data types for large volumes of data. They are known as Large object (LOB). Varbinary (MAX) is the data type that allows you to deal with large binary data. LOB type using this SQL Server Data Type is Binary Large Objects (BLOB).
FILESTREAM integrates the SQL Server Database Engine with an NTFS file system by storing BLOB data as files on the file system. Transact-SQL statements can insert, update, query, search, and back up FILESTREAM data. To improve the performance of Database engine, FILESTREAM caches file data using NT.

There are FILESTREAM filegroups which are used to store data. This filegroup contains file system directories instead of files. These directories are known as data containers. These data containers cannot be nested.

To save file in filestream we have to use FileUpload. It uploads the file and then saves it to Filestream file.

Byte [] buffer = new byte [ (int) FileUpload. FileContent. Length];
FileUpload .FileContent. Read (buffer, 0, buffer.Length);

GET_FILESTREAM_TRANSACTION_CONTEXT is also a newly added feature in SQL Server 2008 which returns current transaction context. To use files stored in Filestream field we have to use SqlFileStream. For that we need to include System. Data. SqlTypes.

No comments:

Post a Comment