I am writing some sort of sync mechanism between a remote Oracle DB and a local Oracle XE DB using ODP.NET. The table i am syncing has a spatial column (and therefore a User Defined Type, sdo_geometry). My logic in C# does a select on the remote database, loops through the result of the OracleDataReader and inserts the results into the local database.
This works like a charm but when the value of the spatial column is DBNull.Value the insert fails with this message:
Object reference not set to an instance of an object.
at Oracle.DataAccess.Client.OracleParameter.PostBind_OracleObject(OracleConnection conn)
at Oracle.DataAccess.Client.OracleParameter.PostBind(OracleConnection conn, OpoSqlValCtx* pOpoSqlValCtx, Int32 arraySize)
at Oracle.DataAccess.Client.OracleCommand.ExecuteNonQuery()
at Gwr.Bsb.Oli.Framework.Helpers.SynchronizationHelper.TryModifyData(OracleCommand cmd)
The code looks something like:
var parameter = new OracleParameter(parameterName, OracleDbType.Object);
parameter.OracleDbType = OracleDbType.Object;
parameter.UdtTypeName = "MDSYS.SDO_GEOMETRY";
parameter.Direction = ParameterDirection.InputOutput;
parameter.Value = reader[i];
As I said earlier. The code works excellent when there is a spatial value. But it fails when the value of reader[i] is DBNull.Value...
Any ideas?