ReadAsync

ReadAsync returns a Task-based asynchronous version of OracleClob.Read(), which reads a specified number of bytes from the ODP.NET LOB instance and populates the buffer.

Overload List:

  • ReadAsync(byte[], int, int, CancellationToken)

    ReadAsync returns a Task-based asynchronous version of OracleClob.Read(), which reads a specified number of bytes from the ODP.NET LOB instance and populates the buffer.

  • ReadAsync(byte[], int, int)

    ReadAsync returns a Task-based asynchronous version of OracleClob.Read(), which reads a specified number of bytes from the ODP.NET LOB instance and populates the buffer.

  • ReadAsync(char[], int, int)

    ReadAsync returns a Task-based asynchronous version of OracleClob.Read(), which reads a specified number of bytes from the ODP.NET LOB instance and populates the buffer.

  • ReadAsync(char[], int, int, CancellationToken)

    ReadAsync returns a Task-based asynchronous version of OracleClob.Read(), which reads a specified number of bytes from the ODP.NET LOB instance and populates the buffer.

Example (includes all overloads)

using Oracle.ManagedDataAccess.Client;
using Oracle.ManagedDataAccess.Types;
using System;
using System.Threading;
using System.Threading.Tasks;

namespace AsyncApp
{
  class AsyncDemo
  {
    static async Task Main(string[] args)
    {
      string connectionString = "User Id=HR; Password=<PASSWORD>; Data Source=oracle;";

      OracleConnection oc = new OracleConnection(connectionString);
      await oc.OpenAsync(CancellationToken.None);

      OracleCommand cmd = oc.CreateCommand();
      cmd.CommandText = " select clob_column from tab1";


      OracleDataReader reader = await cmd.ExecuteReaderAsync();

      await reader.ReadAsync(CancellationToken.None);

      using (var clob = reader.GetOracleClob(0))
      {
        char[] charBuffer = new char[128];
        byte[] byteBuffer = new byte[128];

        //asynchronously read clob data
        int bytesRead = await clob.ReadAsync(byteBuffer, 0, 64);
        Console.WriteLine("Bytes Read: " + bytesRead);

        //asynchronously read clob data
        bytesRead = await clob.ReadAsync(byteBuffer, 64, 64, CancellationToken.None);
        Console.WriteLine("Bytes Read: " + bytesRead);

        //asynchronously read clob data
        int charsRead = await clob.ReadAsync(charBuffer, 0, 64);
        Console.WriteLine("Chars Read: " + charsRead);

        //asynchronously read clob data
        charsRead = await clob.ReadAsync(charBuffer, 64, 64, CancellationToken.None);
        Console.WriteLine("Chars Read: " + charsRead);
      }
    }
  }
}