Export (0) Print
Expand All
Expand Minimize

Large Binary Object (LOB) Handling by Using ADO.NET

SQL Server 2005

Updated: 5 December 2005

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:\Program Files\Microsoft SQL Server\90\Samples\Engine\Data Access\ADO\Handling LOB using ADONetScenario

Transact-SQL, ADO.NET

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 site.
  • The AdventureWorks database which is included with SQL Server 2005, and is also available at the Mic.
  • The SQL Server 2005 Database Engine samples. These samples are included with SQL Server 2005. You can download the latest version of the samples at the Microsoft SQL Server Develo.
  • .NET Framework SDK 2.0 or Microsoft Visual Studio 2005. You can obtain .NET Framework SDK free of charge. For more information, see Installing the .NET Framework SDK.

If you have not already created a strong name key file, generate the key file using the following instructions.

  1. Open a Microsoft Visual Studio 2005 command prompt. Click Start, point to All Programs, point to Microsoft .NET Framework SDK 2.0, and then click SDK Command Prompt.

    -- or --

    Open a Microsoft .NET Framework command prompt. Click Start, point to All Programs, point to Microsoft .NET Framework SDK 2.0, and then click SDK Command Prompt.

  2. Use the change directory command (CD) to change the current directory of the command prompt window to the folder where the samples are installed.
    ms160754.note(en-US,SQL.90).gifNote:
    To determine the folder where samples are located, click the Start button, point to All Programs, point to Microsoft SQL Server, point to Documentation and Tutorials, and then click Samples Directory. If the default installation location was used, the samples are located in <system_drive>:\Program Files\Microsoft SQL Server\100\Samples.
  3. At the command prompt, run the following command to generate the key file:

    sn -k SampleKey.snk

    ms160754.note(en-US,SQL.90).gifImportant:
    For more information about the strong-name key pair, see "Security Briefs: Strong Names and Security in the .NET Framework" in the .NET Development Center on MSDN.

To build the sample, you must do the following:

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

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

    This script creates the following:

    • usp_InsertDocument stored procedure
    • usp_GetDocumentByID stored procedure
  2. Build the application by using Visual Studio 2005 or type the following in a Command Prompt window:

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

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

  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:

    handling_lob_using_adonet /in:.\DataFiles\testdoc.doc /out:otestdoc.doc
    
    ms160754.note(en-US,SQL.90).gifNote:
    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.

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.

ms160754.note(en-US,SQL.90).gifNote:
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.

Release History

5 December 2005

Changed content:
  • Changed instructions for generating a key file, including the name and location of the key file.

Community Additions

ADD
Show:
© 2014 Microsoft