Export (0) Print
Expand All

OracleBFile Class

Note: This namespace, class, or member is supported only in version 1.1 of the .NET Framework.

Represents a managed OracleBFile object designed to work with the Oracle BFILE data type. This class cannot be inherited.

For a list of all members of this type, see OracleBFile Members.

System.Object
   System.MarshalByRefObject
      System.IO.Stream
         System.Data.OracleClient.OracleBFile

[Visual Basic]
NotInheritable Public Class OracleBFile
   Inherits Stream
   Implements ICloneable, INullable
[C#]
public sealed class OracleBFile : Stream, ICloneable, INullable
[C++]
public __gc __sealed class OracleBFile : public Stream, ICloneable,
   INullable
[JScript]
public class OracleBFile extends Stream implements ICloneable,
   INullable

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

The Oracle BFILE data type is an Oracle LOB data type that contains a reference to binary data with a maximum size of 4 gigabytes. An Oracle BFILE differs from other Oracle LOB data types in that its data is stored in a physical file in the operating system instead of on the server. Note that the BFILE data type provides read-only access to data. Therefore, write-oriented methods inherited from the Stream class are not supported.

Other characteristics of a BFILE data type that distinguish it from a LOB data type are that it:

  • Contains unstructured data.
  • Supports server-side chunking.
  • Uses reference copy semantics. For example, if you perform a copy operation on a BFILE, only the BFILE locator (which is a reference to the file) is copied. The data in the file is not copied.

The BFILE data type should be used for referencing LOB s that are large in size, and therefore, not practical to store in the database. There is client, server, and communication overhead for using a BFILE data type compared to the LOB data type. It is more efficient to access a BFILE if you only need to obtain a small amount of data. It is more efficient to access database-resident LOB s if you need to obtain the entire object.

Each non-NULL OracleBFile object is associated with two entities that define the location of the underlying physical file:

  1. An Oracle DIRECTORY object, which is a database alias for a directory in the file system, and
  2. The file name of the underlying physical file, which is located in the directory associated with the DIRECTORY object.

After a BFILE is created, you can retrieve its locator in the form of an OracleBFile object using the ExecuteReader or ExecuteScalar methods.

To obtain an OracleBFile object, call the GetOracleBFile method.

The physical file that an OracleBFile object is associated with does not need to exist until you attempt to access it. An application can bind an OracleBFile to a non-existing file, create the physical file in the expected location, and then call Read.

Any attempt to access a closed OracleBFile using the Read or Seek methods reopens an OracleBFile stream automatically.

The following C# example demonstrates how you can create a BFILE in an Oracle table, and then retrieve it in the form of an OracleBFile object. The example demonstrates the use of the OracleDataReader object and the OracleBFile Seek and Read methods.

using System;
using System.IO;
using System.Data;
using System.Data.OracleClient;
public class Sample
{
    public static void Main(string[] args)
    {
        OracleConnection myConnection = new OracleConnection("Data Source=Oracle8i;Integrated Security=yes ");
        myConnection.Open();
        OracleCommand myCommand = myConnection.CreateCommand();
        myCommand.CommandText = "create or replace directory MyDir as 'c:\\bfiles'";
        myCommand.ExecuteNonQuery();
        myCommand.CommandText = "create table MyTable(col1 number, col2 BFILE)";
        myCommand.ExecuteNonQuery();
        myCommand.CommandText = "insert into MyTable values ('2', BFILENAME('MYDIR', 'MyFile.jpg'))";
        myCommand.ExecuteNonQuery();
        myCommand.CommandText = "select * from MyTable";
        byte[]              buffer = new byte[100];
        OracleDataReader myReader = myCommand.ExecuteReader();
        using (myReader) {
            if (myReader.Read()) {
                   OracleBFile myBFile = myReader.GetOracleBFile(1);
                using (myBFile) {
                    myBFile.Seek(0, SeekOrigin.Begin);
                    myBFile.Read(buffer, 0, 100);
                }
            }
        }
        myConnection.Close();
    }
}

For more information about creating and using an Oracle BFILE, see the appropriate topic in your Oracle documentation.

Note   The BeginWrite, EndWrite, and WriteByte methods, which are inherited from the System.IO.Stream class, are not supported because the BFILE data type is read-only.

Requirements

Namespace: System.Data.OracleClient

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System.Data.Oracleclient (in System.Data.Oracleclient.dll)

See Also

OracleBFile Members | System.Data.OracleClient Namespace

Show:
© 2014 Microsoft