Search code examples
c#stored-proceduresuser-defined-typesoracle-manageddataaccess

Unsupported column datatype from the user-defined type


I don't know what I am missing for the ManagedDataAccess to complain about "Unsupported column datatype". I love how the error does not point out what type or what "column" is giving it grief. Can someone review the code below and let me know what did I miss? Thank you very much!

The table

CREATE TABLE "PORTAL_OPS"."SHAPE" 
(   
 "SIDES" NUMBER(1,0) NOT NULL ENABLE
) 

The type

create or replace type shapeudt as object 
( 
  sides number(1,0)
)

The class

[OracleCustomTypeMappingAttribute("PORTAL_OPS.SHAPEUDT")]
public class Shape : IOracleCustomType, IOracleCustomTypeFactory
{
    [OracleObjectMappingAttribute("SIDES")]
    public Int32 sides;


    public void FromCustomObject(OracleConnection con, IntPtr pUdt)
    {
        OracleUdt.SetValue(con, pUdt, "SIDES", sides);
    }
    public void ToCustomObject(OracleConnection con, IntPtr pUdt)
    {
        sides = (int)OracleUdt.GetValue(con, pUdt, "SIDES");
    }

    public IOracleCustomType CreateObject()
    {
        return new Shape();
    }
}

Calling the UDT to the procedure:

// setting up the parameter
OracleParameter param = new OracleParameter();
param.Direction = ParameterDirection.Input;
//param.UdtTypeName         = udt.DatabaseTypeName;
param.DbType = DbType.Object;
// this needs to stay at the end...if you move it ahead of the
// previous line, you will get 
// "Value does not fall within the expected range" error
param.Value = udt;

Command.CommandText = "portal_ops.PROC_CREATE_SHAPE";
Command.CommandType = CommandType.StoredProcedure;
Command.Parameters.Add(param);

if (Command.Connection.State == ConnectionState.Closed)
{
    Command.Connection.Open();
}

Command.ExecuteNonQuery();

Command.Dispose();

Command.Connection.Close();

Solution

  • Solved it!

    Cause: Not using the right OracleDbType. For the UDT, you HAVE to use OracleDbType.Object when you are defining the OracleParameter. If you are like me, trying to be a fan of Oracle's Managed Driver. Well, you are SOL, because the as of version 19.6, Oracle Managed Data Access Nuget still does not support OracleDbType.Object.

    Solution: Switch to the Unmanaged Driver. Yes, you'll have to break up w/ the Managed Driver. Down the VS tool from here. Yes, the twist is you HAVE to use the one installed by Oracle Universal Installer (OUI).