Readme_Send and Receive Data Incrementally with FILESTREAM (ODBC)
[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]
This sample works only with SQL Server 2008. It will not work with any version of SQL Server earlier than SQL Server 2008.
This sample shows how to use the FILESTREAM feature to send and receive data incrementally with SQLPutData and SQLGetData.
SQL Server samples and sample databases must be downloaded and installed before you can view or work with them. For more information, see Considerations for Installing SQL Server Samples and Sample Databases.
Scenario
For more information about the FILESTREAM feature, see FILESTREAM Support (ODBC) in SQL Server Books Online.
Languages
This sample uses Visual C++.
Prerequisites
Before running this sample, make sure the following software is installed:
- SQL Server or SQL Server Express, including Database Engine.
You can download SQL Server Express from the Microsoft Download Center. - The SQL Server Database Engine samples that are available at the Microsoft SQL Server Developer Center.
- .NET Framework SDK 2.0 (or later) or Microsoft Visual Studio 2005 (or later). You can obtain .NET Framework SDK free of charge. For more information, see Installing the .NET Framework Documentation.
- Ensure that FILESTREAM support is enabled. In the SQL Server Configuration Manager, right-click on the name of your SQL Server instance. On the FILESTREAM tab, enable the options.
Building the Sample
You must specify a server. In ODBC_filestream.cpp, change "MyServer" to a valid server name.
Make sure your INCLUDE environment variable includes the directory that contains sqlncli.h.
The sample requires you to execute the following stored procedure, which you can find in the sample's scripts directory:
USE master GO -- Enable FILESTREAM. exec sp_configure 'filestream access level', 2 GO -- Create directory for FILESTREAM database. EXEC sp_configure 'show advanced options', 1 GO RECONFIGURE GO EXEC sp_configure 'xp_cmdshell', 1 GO RECONFIGURE GO EXEC xp_cmdshell 'md c:\filestreamdemo' GO -- Drop the FILESTREAM demo database. IF EXISTS (SELECT name FROM master..sysdatabases WHERE name = 'myfilestreamdb') DROP DATABASE [myfilestreamdb] GO -- Create the FILESTREAM demo database. CREATE DATABASE [myfilestreamdb] ON PRIMARY (NAME=[myfilestreamdbprimary], FILENAME='c:\filestreamdemo\dbf.mdf'), FILEGROUP [fsgrp] CONTAINS FILESTREAM (NAME=[fscnt],FILENAME='c:\filestreamdemo\fscnt') LOG ON (NAME=[dblog], FILENAME='c:\filestreamdemo\db1.ldf', SIZE=5MB, MAXSIZE=3000MB, FILEGROWTH=5MB) GO -- Create a table that contain a FILESTREAM column. CREATE TABLE [myfilestreamdb]..[mydocs] ( id UNIQUEIDENTIFIER ROWGUIDCOL NOT NULL UNIQUE, doc VARBINARY(MAX) FILESTREAM ) GO
In SQL Server Management Studio, load and execute the Scripts\setup.sql script or execute the following command in a Command Prompt window:
sqlcmd -E -I -i Scripts\setup.sql
If you are using Visual Studio, load the ODBC_filestream.sln file and build it.
If you are using MSBuild.exe, invoke MSBuild.exe at a command prompt. Pass in the ODBC_filestream.sln file, as follows:
MSBuild ODBC_filestream.sln
Running the Sample
- From Visual Studio, invoke Start Without Debugging (CTRL+F5).
- If you built with MSBuild.exe, invoke ODBC_filestream.exe.
Deleting the Sample Database
To delete the database in c:\filestreamdemo, you have to detach the database in SQL Server Management Studio, as follows:
USE MASTER
GO
-- Drop the FILESTREAM demo database.
sp_detach_db 'myfilestreamdb'
IF EXISTS (SELECT name FROM master..sysdatabases WHERE name = 'myfilestreamdb')
DROP DATABASE [myfilestreamdb]
EXEC xp_cmdshell 'rd /s /q c:\filestreamdemo'
GO