Skip to Main Content

ODP.NET

Announcement

For appeals, questions and feedback, please email oracle-forums_moderators_us@oracle.com

OracleBlob.Value throws exception after executing a stored procedure on Managed ODP.NET

I was put in charge of migrating our software from native ODP.NET to the managed ODP.NET, all parts of the software are now using the managed client and functioning properly so far.

The problem is in one method, we're getting a document from the database (DbType Blob) by executing a stored procedure, when I try to access the value of the output parameter (type OracleBlob) it throws this exception:

{"ORA-12571: TNS:packet writer failure"}
Oracle.ManagedDataAccess.Client.OracleException: 'ORA-12537: TNS:connection closed
https://docs.oracle.com/error-help/db/ora-12537/'

This wasn't an issue with the native odp.net. The connection and command are set up correctly. There are other OracleBlob member fields that throw an exception like IsEmpty, Length, ReadTimeout.

This is my code, maybe I'm missing something:

public byte[] GetDocumentContent(long id)
{
    byte[] result = null;
    OracleBlob blob = null;
    OracleParameter blobImage;

    using (OracleConnection con = new OracleConnection(_conString))
    {
        con.Open();
        using (OracleCommand cmd = new OracleCommand("get_document_content", con))
        {
            cmd.CommandType = System.Data.CommandType.StoredProcedure;

            cmd.Parameters.Add("p_document_content_id", OracleDbType.Int64, ParameterDirection.Input).Value = id;

            blobImage = cmd.Parameters.Add("p_document_image", OracleDbType.Blob);
            blobImage.Direction = ParameterDirection.Output;

            cmd.ExecuteNonQuery();

            if (((OracleBlob)blobImage.Value).IsNull == false)
            {
                blob = (OracleBlob)blobImage.Value;
                result = blob.Value;
            }
        }
        con.Close();
    }
    return result;
}
This post has been answered by Alex Keh-Oracle on Jan 18 2024
Jump to Answer
Comments
Post Details
Added on Jan 17 2024
4 comments
54 views