Sql-server – File stream in SQL Server 2008

filestreamsql-server-2008

Hello all I referred to this https://stackoverflow.com/a/5613926/842112

In that they mentioned this

if your pictures or document are typically over 1 MB in size, storing
them in the filesystem is more efficient (and with SQL Server 2008's
FILESTREAM attribute, they're still under transactional control and
part of the database)

Now my question is how to use File stream attribute in SQL Server 2008? I referred to http://msdn.microsoft.com/en-us/library/cc949109.aspx but I don't get how to use this. So please suggest me how to use this I want to store images in a database table. Thank you.

Best Answer

To use FILESTREAM, it has to be configured at the OS and instance level. At the OS level, FILESTREAM is enabled either during the installation of SQL Server 2008 or by running SQL Server Configuration Manager. Once FILESTREAM has been setup, you have to create a FILESTREAM filegroup. You then have to create a data container in the FILESTREAM filegroup. Once all these steps are done, you can create a table in your DB to use FILESTREAM.

(From your link) Here are the steps to configure FILESTREAM at the OS level, if not done during installation:

  1. On the Start menu, point to All Programs, point to Microsoft SQL Server 2008, point to Configuration Tools, and then click SQL Server Configuration Manager.
  2. In the list of services, right-click SQL Server Services, and then click Open.
  3. In the SQL Server Configuration Manager snap-in, locate the instance of SQL Server on which you want to enable FILESTREAM.
  4. Right-click the instance and then click Properties.
  5. In the SQL Server Properties dialog box, click the FILESTREAM tab.
  6. Select the Enable FILESTREAM for Transact-SQLAccess check box.
  7. If you want to read and write FILESTREAM data from Windows, click Enable FILESTREAM for file I/O streaming access.
  8. Enter the name of the Windows share in the Windows Share Name box.
  9. If remote clients must access the FILESTREAM data that is stored on this share, select Allow remote clients to have streaming access to FILESTREAM data. Click Apply.

Next configure the SQL instance for FILESTREAM access. Run the following query on the instance (SSMS):

EXEC sp_configure filestream_access_level, 2; -- Options are 0/1/2
GO
RECONFIGURE;
GO

Now add the FILESTREAM filegroup to your DB:

ALTER DATABASE Production ADD
FILEGROUP FileStreamGroup1 CONTAINS FILESTREAM;
GO

ALTER DATABASE Production ADD FILE (
       NAME = FSGroup1File,
       FILENAME = 'F:\Production\FSDATA') -- Location for your data container 
TO FILEGROUP FileStreamGroup1;
GO

You can now use FILESTREAM in your tables.