The LOB_ADONet sample programmatically reads binary data from a file and stores the contents into a database. This sample also retrieves binary data stored in the database and writes the contents to a file.

Default Location: [drive:]C:\Program Files\Microsoft SQL Server\90\Samples\Engine\Data Access\ADO\Handling LOB using ADONetScenario

Languages

Transact-SQL, ADO.NET

Prerequisites

Before you run this sample, make sure the following software is installed:

  • SQL Server 2005 or SQL Server 2005 Express Edition. You can obtain SQL Server 2005 Express Edition free of charge from this Microsoft Web siteMicrosoft Web site.

  • The AdventureWorks sample database that is included with SQL Server 2005. This sample database is available at this Microsoft Web site.

  • The SQL Server 2005 Database Engine samples. These samples ship with SQL Server 2005 and also ship within the Microsoft .NET Framework 2.0 SDK.

  • .NET Framework SDK 2.0 or Microsoft Visual Studio 2005. You can obtain .NET Framework SDK free of charge. See Installing the .NET Framework SDK.

Building the Sample

To build the sample, you must do the following:

Build the sample

  1. In SQL Server Management Studio, load and execute the Scripts\install.sql script or execute the following command in a Command Prompt window:

    Copy Code
    sqlcmd -E -I -i Scripts\installCS.sql

    This script creates the following:

    • usp_InsertDocument stored procedure

    • usp_GetDocumentByID stored procedure

  2. CD to the install directory and execute the following at a .NET Framework or Microsoft Visual Studio 2005 command prompt:

    sn -k LOB.snk

  3. Build the application by using Visual Studio 2005 or type the following in a Command Prompt window:

    Copy Code
       msbuild /nologo /verbosity:quiet /property:Configuration=Debug  CS\Handling LOB using ADONet\Handling LOB using ADONet.csproj

    Copy Code
       msbuild /nologo /verbosity:quiet /property:Configuration=Debug VB\Handling LOB using ADONet\Handling LOB using ADONet.vbproj

Running the Sample

To run the sample

  1. Run bin\Release\handling_lob_using_adonet.exe (or bin\Debug\handling_lob_using_adonet.exe). Optionally, you can provide the input file name, output file name and the database server name. The default values for input parameters are:

    • String currentDirectory = Directory.GetCurrentDirectory() + @"\";

    • String inFileName = "testdoc.doc";

    • String outFileName = "docout.doc";

    • String dataSource = "localhost";

  2. In the Command Prompt window, type:

    Copy Code
    handling_lob_using_adonet /in:.\DataFiles\testdoc.doc /out:otestdoc.doc
    Note:
    The default current directory will be .\bin\debug. If you run the sample from Visual Studio, you may have to move testdoc.doc to this directory.

Comments

This sample reads data from the testdoc.doc input file into the Document table in the AdventureWorks sample database. The sample retrieves data from the Document table and reads it into the docout.doc output file.

Note:
By default, the test.doc input file is in the Data Files folder, and the docout.doc output file is written to the Application Data folder.