I am trying to migrate a .Net 4.5.2 application from using Microsoft's deprecated System.Data.OracleClient dll to using Oracle's own Oracle.ManagedDataAccess.dll (using the Nuget package v12.1.1.24160419). On the machine in question I have the Oracle client installed, and I have a tnsnames.ora file set up which the original app successfully uses to connect. I can also successfully connect with Oracle's SqlPlus and SqlDeveloper tools. However if I try to use the Oracle dll my application cannot connect.
To distill this down to the very basics I have created a very simple console application (code below) to see what is going on. If the project references the Microsoft dll (with the appropriate using statement) it will connect, but if instead I reference the Oracle.ManagedDataAccess.dll (with the appropriate using statement) it complains about a TNS error:
ORA-12504: TNS:listener was not given the SERVICE_NAME in CONNECT_DATA
I've tried adding a SERVICE_NAME clause to the tnsnames.ora file but with no improvement.
What else do I need to do?
Test app is:
using Oracle.ManagedDataAccess.Client;
using System;
using System.Collections.Generic;
//using System.Data.OracleClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace oracleconnect
{
class Program
{
static void Main(string[] args)
{
try
{
InitializeDBConnection();
}
finally
{
if (_con.State==System.Data.ConnectionState.Open)
_con.Close();
}
}
static private OracleConnection _con;
private const string connectionString = "Data Source=oracledbserver2;User ID=MATTESTNHSYS;Password=thePassword";
private static void InitializeDBConnection()
{
_con = new OracleConnection();
_con.ConnectionString = connectionString;
_con.Open();
}
}
}