It looks like there’s a possible bug in odp.net 10.2.0.3.0 x64, calling a server that is on 10.2.0.3.
The code below works as expected using odp.net x86 10.2.0.4.0.
If an OracleCommand object is instantiated before the first OracleConnection object for the process is created, and an ExecuteReader or ExecuteDataSet is attempted on the command object, the following exception is thrown:
Oracle.DataAccess.Client.OracleException ORA-24338: statement handle not executed at Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, String procedure)
at Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, OracleConnection conn, String procedure, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src)
at Oracle.DataAccess.Client.OracleCommand.ExecuteReader(Boolean requery, Boolean fillRequest, CommandBehavior behavior)
at Oracle.DataAccess.Client.OracleCommand.ExecuteReader()
at CreateCommandBeforeFirstConnectionConsole.Program.Main(String[] args) in C:\projects\OracleTestWebService\CreateCommandBeforeFirstConnectionConsole\Program.cs:line 28
Here’s a .net console app that demonstrates the problem – this was built and run on an x64 windows server 2003 box using the .net 2.0 framework. This works without exception on windows xp 32-bit using odp.net 10.2.0.4.0.
using System;
using System.Collections.Generic;
using System.Text;
using Oracle.DataAccess.Client;
using System.Data;
namespace CreateCommandBeforeFirstConnectionConsole
{
class Program
{
static void Main(string[] args)
{
try
{
Console.WriteLine("Creating command");
using (OracleCommand cmd = new OracleCommand())
{
cmd.CommandText = "select sysdate from dual";
cmd.CommandType = CommandType.Text;
using (OracleConnection conn = new OracleConnection())
{
conn.ConnectionString = "data source=foo;user id=foo;password=foo;";
conn.Open();
cmd.Connection = conn;
using (OracleDataReader dr = cmd.ExecuteReader())
{
dr.Read();
Console.WriteLine(dr.GetDateTime(0));
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
Console.WriteLine("Press
Enter to exit.");
Console.ReadLine();
}
}
}