1

I am getting this error(I am using Oracle.DataAccess dll):

{Oracle.DataAccess.Client.OracleConnection}

(Oracle.DataAccess.Client.OracleException).DataSource threw an exception of type 'System.NullReferenceException'

StackTrace :

at Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32
errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx*
pOpoSqlValCtx, Object src, String procedure, Boolean bCheck, Int32
isRecoverable)
   at Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode,
OracleConnection conn, IntPtr opsErrCtx, Object src)
   at Oracle.DataAccess.Client.OracleConnection.Open()

Code:

 using (OracleConnection conn = new OracleConnection(ConfigurationManager.ConnectionStrings["myConnection"].ConnectionString))
            {
                using (OracleCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "<<Procedure Name>>";
                    cmd.Parameters.Add("v_cur", OracleDbType.RefCursor).Direction = ParameterDirection.Output;

                    conn.Open(); --line throws exception
                    using (OracleDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            retVal = reader["VALUE"].ToString();
                        }
                        reader.Close();
                    }
                }
            }

Any inputs will be helpful? thanks.

5
  • You never shared the actual error message. Commented Jun 29, 2016 at 18:22
  • Updated, thank you. Commented Jun 29, 2016 at 18:39
  • 2
    One thing you can try if you have not, is to run the managed (Oracle.ManagedDataAccess.dll) version of the DLL instead of the non managed, I have found that it fixes some of my weird oracle connection issues. The managed version is self contained, does not depend on Oracle client and it works on 32 and 64 bit seamlessly Commented Jun 30, 2016 at 19:58
  • Thanks Omaraguirre. Did that, it connected, thanks. Put that as your response, i will accept that answer. Commented Jun 30, 2016 at 21:00
  • I am glad it worked, those types of issues can drive a person nuts Commented Jun 30, 2016 at 21:24

3 Answers 3

5

I downloaded ODAC121021Xcopy_32bit from Oracle site and extracted the zip and installed using the install.bat file.

I did faced the same issue. Thanks Omaraguirre. As stated by Omaraguirre, referenced the Oracle.ManagedDataAccess.dll and the issue got fixed. I could able to open the connection without any issue.

But I wanted to figure out why Oracle.DatAccess.dll throws Null reference exception while trying to open the connection. I found that the supporting dlls like (oci.dll, ociwin32.dll etc.) are required to open up the connection without error. So I copied all the dll files from instantclient_12_1(this folder is found inside the extracted ODAC121021Xcopy_32bit folder) folder to oracle installed bin directory (C:\oracle\bin, in my machine). Now the Oracle.DataAccess.dll doesn't throw error when opening the connection.

One more thing is Oracle.ManagedDataAccess.dll will load all supporting dll files internally. But Oracle.DataAccess.dll requires the supporting dlls to be present in the executing app directory (in case of console/WinForm apps) or oracle installed bin directory (in case of Web app). Difference between Oracle.DataAccess.dll and Oracle.ManagedDataAccess.dll dlls can be found @ https://docs.oracle.com/database/121/ODPNT/intro003.htm#ODPNT131

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks !! i've been struggling for a couple day ! In addition, ManagedDataAccess does not handle UDT
Oracle.ManagedDataAccess.dll does not load other supporting dll files internally (maybe apart from Windows system internals). It is a stand-alone DLL which does not require any other installation.
2

One thing you can try if you have not, is to run the managed (Oracle.ManagedDataAccess.dll) version of the DLL instead of the non managed, I have found that it fixes some of my weird oracle connection issues. The managed version is self contained, does not depend on Oracle client and it works on 32 and 64 bit seamlessly

Comments

1

Tried the suggestion that omaraguirre user suggested in the comment.

Just followed these steps, it might help.

  1. Delete existing reference to Oracle.DataAccess from your project and add a new Oracle.ManagedDataAccess.dll from the downloaded folder: odp.net\managed\common\Oracle.ManagedDataAccess.dll.

  2. Set it's property Copy Local = True so it will be deployed along with your project.

  3. Don't forget to add a new "using" line to your code: using Oracle.ManagedDataAccess.Client;

  4. You can change the project platform target to AnyCPU now and it will work.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.