ODAC: Object reference not set to an instance of an object
Asked Answered
E

3

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?

Engud answered 9/11, 2015 at 19:4 Comment(1)
Please show a complete stack trace.Exaction
T
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.

Tasse answered 3/4, 2019 at 18:19 Comment(1)
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.Tumble
P
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

Pernickety answered 3/4, 2019 at 18:27 Comment(0)
N
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.
Nightgown answered 7/8, 2017 at 15:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.