7

I am trying to connect to Oracle Express 11g. I am using ODAC 12c with Visual Studio 2015. Here's how I am trying to connect:

OracleConnection con;
con = new OracleConnection("User Id=SYSTEM;Password=manager;Data Source=(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.1.22)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAME = XE)))");
con.Open();

Application crashes and give Exception (not OracleException) : Object reference not set to an instance of an object. If I do not set connection string, it gives OracleException as expected. What's wrong?

Nikita Zernov
  • 5,465
  • 6
  • 39
  • 70

3 Answers3

6

Please make sure reference are correct and Oracle.DataAccess.dll is of correct version.

Please follow below steps. It worked for me.

  1. Locate and copy the oraons.dll file in ‘<>product\12.2.0\client_1’ on your oracle install path

  2. Paste the file into the ‘<>product\12.2.0\client_1\bin directory

Try calling the code again.

ZKS
  • 817
  • 3
  • 16
  • 31
  • That DLL's already in the "...\bin" path under the client, and he's using ODAC; does he even have the client installed? That DLL is also in the ODAC "\bin" path. – galaxis Jun 14 '22 at 15:59
1

please try this solution :

string connString = "User Id=SYSTEM;Password=manager;Data Source=(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.1.22)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAME = XE)))";

OracleConnection conn = new OracleConnection();
conn.ConnectionString = connString;
conn.Open();

For more informations : Oracle Connection in C# - connection string

0

OracleConnection Uses Oracle.DataAccess DLL (Its deprecated, read about ODP.net)

You probably have to install oracle client 11g to provide the neccessery DLL. A few points:

  1. Make sure that tns is configure correctly
  2. install the ora client by your build settings (32/64 bit)
  3. Make sure you add the DLL reference to your solution.
fatalica
  • 117
  • 9