views:

186

answers:

1

I'm learning how to work with Oracle and am using C#/Visual Studio. Just as a reference, I'm following this simple tutorial, and have all the prerequisites done (database installed and ODAC with dev tools installed). The following code that's supposed to create an object for connection to a database throws an exception saying "Object reference not set to an instance of an object." and points to 'conn' when I try to run the program:

OracleConnection conn = new OracleConnection ();

The same thing happens regardless of whether I pass the connection string as a parameter or not. I have the needed Oracle.DataAccess reference set, so I don't know if I could be missing something else?

The database is installed and works, but that shouldn't have to do anything with this problem.

A: 

I remember having difficulties getting the Oracle Data Provider up and running with C# at first too. My tnsnames.ora file exsted in C:\oracleInstallDir\10.2.0\client_1\NETWORK\ADMIN directory.

My tnsnames.ora looked like this:

XE=
(DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)))

Make sure that you have the Oracle.DataAccess reference added to your C# project.

Then also make sure that you are

using Oracle.DataAccess.Client;

public class OracleMgr{
  public OracleMgr(){
    string connectionStr = "Data Source=XE;User Id=user1;Password=abc";
    OracleConnection conn = new OracleConnection(connectionStr);
    do stuff...
  }
}
Dave