Skip to Main Content

ODP.NET

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Using ODP.NET for Oracle 12.2c with IPC connections: NullReferenceException

User_LYW8JSep 12 2017 — edited Sep 18 2017

After installing Oracle 12c Release 2, I am running into some problems with database and transaction handling. The version of the `ODP.NET` dll (`Oracle.DataAccess.dll`) is 4.122.1.0, and I am using a PC with Windows 7 Professional.

I am no longer able to use the `OracleConnection.State` property to monitor the state of a connection, which breaks existing code. 
It seems that simply accessing the State property corrupts the `OracleConnection` object, but only when using `IPC` connections. Below is a code example that reproduces the problem. The database in this example is run on my local system.

private const string ConnectionStringIPC = @"Data Source=(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = IPC)(Key = EXTPROC1521))) (CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAME = GLOBAL)));User Id=TestCase;Password=TestCase;Validate Connection=true;";
private const string ConnectionStringTCP = @"Data Source=(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))) (CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAME = GLOBAL)));User Id=TestCase;Password=TestCase;Validate Connection=true;";

static void Main(string[] args)
{
  Console.WriteLine("IPC:");
  TestCase1(ConnectionStringIPC);
  TestCase2(ConnectionStringIPC);

  Console.WriteLine("TCP:");
  TestCase1(ConnectionStringTCP);
  TestCase2(ConnectionStringTCP);
}

private static void TestCase1(string connectionString)
{
  try
  {
   OracleConnection conn = new OracleConnection(connectionString);
   conn.Open();
   OracleTransaction trans = conn.BeginTransaction();

   Console.WriteLine("TestCase1 succesful!");
  }
  catch(Exception e)
  {
   Console.WriteLine("TestCase1 failed:");
   Console.WriteLine(e.Message);
   Console.WriteLine(e.StackTrace);
  }
}

private static void TestCase2(string connectionString)
{
  try
  {
   OracleConnection conn = new OracleConnection(connectionString);
   conn.Open();
   var state = conn.State;
   OracleTransaction trans = conn.BeginTransaction();

   Console.WriteLine("TestCase2 succesful!");
  }
  catch (Exception e)
  {
   Console.WriteLine("TestCase2 failed:");
   Console.WriteLine(e.Message);
   Console.WriteLine(e.StackTrace);
  }
}

The output of this program is

IPC:
TestCase1 succesful! 
TestCase2 failed: 
Object reference not set to an instance of an object. 
    at Oracle.DataAccess.Client.OracleConnection.get_TxnHndAllocated() 
    at Oracle.DataAccess.Client.OracleConnection.BeginTransaction() 
    at OracleConnectionTest.Program.TestCase2(String connectionString) 
TCP: 
TestCase1 succesful! 
TestCase2 succesful!

As you can see, simply accessing the `OracleConnection.State` property is enough to invalidate the object, triggering an exception in the subsequent `OracleTransaction.BeginTransaction` call.

Is there anything wrong with the way I try to use the `OracleConnection` and `OracleTransaction` objects?
If not, is this a known bug, and is there any good work-around?

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 10 2017
Added on Sep 12 2017
0 comments
670 views