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?