0

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?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
TurBas
  • 1,646
  • 13
  • 15

1 Answers1

0

Funny stuff... I am looking at the wrong direction.

The problem is not at the insert but it emerge when the insert is executed. The problem has something to do with the parameter direction. It seems that the code can't handle the output direction of the parameter. When I changed it everything started to work again.

So problem solved for now.

TurBas
  • 1,646
  • 13
  • 15