title: Error when trying to connect to Oracle 10g database from C# program employing minimal set-up configuration
body: <p>I'm experiencing an error when trying to connect to a remote Oracle 10g database from a C# 2008 Express Edition application I'm developing. I'm trying to use a minimalist, non-intrusive approach to the development with a view to ClickOnce deployment to user workstations.</p>
  
  <p>In respect of the above I've investigated the following documents (amongst others..) -</p>
  
  <p><a href="https://stackoverflow.com/questions/923283/what-is-the-minimal-setup-required-to-deploy-a-net-application-with-oracle-clie/923300#923300">What is the minimal setup required to deploy a .NET application with Oracle client 11?</a></p>
  
  <p><a href="http://jeremybranham.wordpress.com/2011/04/25/oracle-instant-client-with-odp-net/" rel="nofollow noreferrer">http://jeremybranham.wordpress.com/2011/04/25/oracle-instant-client-with-odp-net/</a></p>
  
  <p><a href="http://ora-00001.blogspot.com/2010/01/odpnet-minimal-non-intrusive-install.html" rel="nofollow noreferrer">http://ora-00001.blogspot.com/2010/01/odpnet-minimal-non-intrusive-install.html</a></p>
  
  <p><a href="http://splinter.com.au/using-the-new-odpnet-to-access-oracle-from-c" rel="nofollow noreferrer">http://splinter.com.au/using-the-new-odpnet-to-access-oracle-from-c</a></p>
  
  <p><a href="https://stackoverflow.com/questions/5647137/connect-to-oracle-with-odp-net-and-the-oci-from-c-sharp">Connect to Oracle with odp.net and the OCI from C#</a></p>
  
  <p>In view of the error I've experienced I've created a simple test app. consisting of a single (wpf) page with one button.
  In the click-event of the button I attempt to create a connection to an Oracle database - </p>
  
  <pre><code>private void button1_Click( object sender, RoutedEventArgs e )
  {
      OracleConnection oraConnect;
  
      // string previously used OK in other projects
      string connectionString = "Data Source=" +
             "(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = myServer)(PORT = 1521)))" +
             "(CONNECT_DATA =(SERVICE_NAME = myOracleDb)))" +
             ";Password=myPw;User ID=myID;";
  
      using ( oraConnect = new OracleConnection( connectionString ) )
      {
          try
          {
              if ( oraConnect.State == ConnectionState.Closed )
              {
                  oraConnect.Open();
                  MessageBox.Show( "oraConnect is attempting to open.." );
              }
              else
                  MessageBox.Show( "oraConnect open to DB: " + oraConnect.ServerVersion.ToString() );
          }
          catch ( NullReferenceException nullExcept )
          {
              MessageBox.Show( "Caught error: ." + nullExcept.ToString() );
          }
          catch ( OracleException dbEx )
          {
              MessageBox.Show( "OraException - " + dbEx.Message.ToString());
          }
          catch ( Exception ex )
          {
              Exception current;
              current = ex;
  
              while ( current != null )
              {
                  current = current.InnerException;
              }
  
              MessageBox.Show( "Db base exception - " + ex.GetBaseException().ToString() );
          }
          finally
          {
              oraConnect.Close();
          }
      }
  }
  </code></pre>
  
  <p>Following the information in the above articles I've ensured that the following Dll's are in my "bin" folder -</p>
  
  <p>•   oci.dll<br>
  •   ociw32.dll<br>
  •   orannzsbb10.dll<br>
  •   oraocci10.dll<br>
  •   oraociicus.dll<br>
  •   msvcr71.dll    </p>
  
  <p>(the last named in desperation...) and have referenced 'Oracle.DataAccess.dll'.</p>
  
  <p>The error message (at 'catch ( OracleException dbEx )') is -</p>
  
  <pre><code>"Oracle.DataAccess.Client.OracleException was caught
    Message=""
    StackTrace:
         at Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, String procedure)
         at Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, Object src)
         at Oracle.DataAccess.Client.OracleConnection.Open()
         at OracleConnectionTest.Window1.button1_Click(Object sender, RoutedEventArgs e) in C:\Documents\Visual Studio 2008\Projects\OracleConnectionTest\OracleConnectionTest\Window1.xaml.cs:line 69
    InnerException: "
  
  Line 69 is 'oraConnect.Open();'.
  </code></pre>
  
  <p>In addition, the following is reported -</p>
  
  <pre><code>"((Oracle.DataAccess.Client.OracleException)($exception)).DataSource' threw an exception of type 'System.NullReferenceException".
  </code></pre>
  
  <p>I'm assuming from the NullReferenceException within the datasource that the problem lies in one of the dlls' (?) as I 'new' the OracleConnection above before trying to reference it.</p>
  
  <p>In addition, the code execution jumps the 'catch ( NullReferenceException nullExcept )'
  and goes straight to the OracleException catch.</p>
  
  <p>Sorry for rambling on but hope this makes sense?
  Any help/advice appreciated!</p>