When reading data from a table that contains a CLOB column using the GetValue method, the performance occurs memory and its unreleased.
Oracle.ManagedDataAccess.dll version 4.122.1.0 was used to connect to the database.
Example:
CREATE TABLE TEST
(
ID INTEGER,
LONG_TEXT CLOB
);
C#:
public static void ReadTest()
{
var connBuilder = new OracleConnectionStringBuilder()
{
UserID = "SCOTT",
Password = "TIGER",
DataSource = "TNSNAME"
};
using (OracleConnection connection = new OracleConnection(connBuilder.ConnectionString))
{
connection.Open();
using (OracleCommand command = connection.CreateCommand())
{
command.CommandText = "SELECT * FROM TEST";
using (OracleDataReader reader = command.ExecuteReader())
{
// Read rows
while (reader.Read())
{
// Read result columns
for (int i = 0; i < reader.FieldCount; i++)
{
// Read column value
var dataValue = reader.GetValue(i); // CLOB is returned as string Type - is not IDisposable
Console.Write("{0}: {1}\t", reader.GetName(i), dataValue?.ToString());
// Set variable to null - for sure
dataValue = null;
}
Console.Write("{0}", Environment.NewLine);
}
}
}
}
}
Issue fix Example:
public static void ReadTest()
{
var connBuilder = new OracleConnectionStringBuilder()
{
UserID = "SCOTT",
Password = "TIGER",
DataSource = "TNSNAME"
};
using (OracleConnection connection = new OracleConnection(connBuilder.ConnectionString))
{
connection.Open();
using (OracleCommand command = connection.CreateCommand())
{
command.CommandText = "SELECT * FROM TEST";
using (OracleDataReader reader = command.ExecuteReader())
{
// Read rows
while (reader.Read())
{
// Read result columns
for (int i = 0; i < reader.FieldCount; i++)
{
// Read column value
var dataValue = reader.GetOracleValue(i);
if (dataValue != null)
{
// Test returned Type
if (dataValue is OracleClob)
{
OracleClob oClob = dataValue as OracleClob;
// Read text
var text = oClob.Value;
Console.Write("{0}: {1}\t", reader.GetName(i), text);
text = null;
oClob?.Close();
}
else if (dataValue is OracleBlob)
{
OracleBlob oBlob = dataValue as OracleBlob;
// Read data
var data = oBlob.Value;
Console.Write("{0}: {1}bytes\t", reader.GetName(i), data?.Length);
data = null;
oBlob?.Close();
}
else
{
Console.Write("{0}: {1}\t", reader.GetName(i), dataValue?.ToString());
}
}
if (dataValue is IDisposable)
((IDisposable)dataValue)?.Dispose();
dataValue = null;
}
Console.Write("{0}", Environment.NewLine);
}
}
}
}
}