I have 32-bit drivers installed on my box (they were installed and configured by some DBAs)
I wrote a simple script to test the drivers which pretty much is as follows
using (DataTable table = new DataTable())
{
using (OracleConnection connection = new OracleConnection())
{
connection.ConnectionString = "Data Source=alias;User id=user;Password=password";
connection.Open();
using (OracleCommand command = connection.CreateCommand())
{
command.CommandType = CommandType.Text;
command.CommandText = "SELECT * FROM DUAL";
table.Load(command.ExecuteReader());
}
}
}
When I compile this application as 32-bit with the 32-bit Oracle.DataAccess.dll, it executes without a hitch.
However if I compile the application as AnyCPU with the Oracle.ManagedDataAccess.dll, i get an ORA-12154 (could not resolve the connect identifier specified) error.
If I tnsping alias, it works correctly and tells me the connect identifier with the real database name.
If I then change the connection string to use the real database name instead of the alias, and then try with the managed library again, it executes without a hitch.
I've been reading around and found this answer which says the managed driver relies on the tnsnames.ora file to resolve the aliases, however I rely on LDAP servers defined in sqlnet.ora and ldap.ora.
When I tnsping, it says it uses sqlnet.ora to resolve the name.
So how come the managed drivers do not work?
ODP.NET Managed driver relies on TNS_ADMIN value being set in the config file to find the TNSNAMES.ORA file. If you don't want to set that value, you can include the TNSNAMES.ORA file in the working directory of the executable or create a TNS alias in the config file directly.
Edit: If you are relying on SQLNET.ORA and LDAP.ORA you can also copy those into the working directory as well, or set the LDAP parameters in your config file. See the ODP.NET doc for the config file parameters available for LDAP.
May this workaround is suitable for you. You can query the LDAP server by your own and put the full connection string to your code.
You can resolve the connection string from LDAP with this code:
...