0

I try to make select from Oracle 11gR2 by using ODP.NET x86.

In ConsoleApplication everthing works perfectly, but if I try make same select in my MVC 4 WebApplication (from dependentcy injected service from ClassLibrary) I get this error: Additional information: The type initializer for 'Oracle.DataAccess.Client.OracleConnection' threw an exception.

I compile app as Any CPU.

Any Idea ? I am lost. Thank s a lot.

ConnectionString

string connectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=kango))); User ID=system; Password=root";

Instantiate

  using (var connection = new OracleConnection(connectionString))
        {
            var command = new OracleCommand(select);
            try
            {
                command.Connection = connection;
                connection.Open();
                OracleDataReader reader = command.ExecuteReader();

                while (reader.HasRows)
                {    ...
                }
            }
         }

In ,,using" line exception is thrown

user2080814
  • 57
  • 2
  • 10
  • What connection string are you using? How do you instantiate the OracleConnection class? – Ricardo Peres Jun 09 '14 at 11:14
  • @user2080814 - please get in the habit of editing the question to add new information. Putting additional information in comments makes it likely that the comment and the additional information will be overlooked by people trying to help. If you would be so kind, please edit your question and add the information about the connection string to the end of the question. Thanks. – Bob Jarvis - Слава Україні Jun 09 '14 at 11:25
  • "The type initializer for 'Oracle.DataAccess.Client.OracleConnection' threw an exception" - Most likely that exception can be found in the `InnerException` property of the exception that you got. Please post the `InnerException` and possibly the full stack trace. – chiccodoro Jun 10 '14 at 06:35

2 Answers2

1

Why didn't you post the exception (error message and call stack)? It often contains crucial information for figuring-out the problem.

Absent that, my hunch is that your "Any CPU" build got executed as 64-bit, which caused it to fail loading 32-bit native Oracle DLLs. Solutions to consider:

  • Either continue using old, "mixed mode" ODP.NET and build for specific bit-ness as shown here.
  • Or use the new, "fully managed" ODP.NET, which is intrinsically "Any CPU".
Community
  • 1
  • 1
Branko Dimitrijevic
  • 50,809
  • 10
  • 93
  • 167
  • If "fully managed ODP.NET" means Oracle.ManagedDataAccess.dll - I tried it, but this library doesn`t work with XMLType and I can not read column of this type. – user2080814 Jun 09 '14 at 12:00
  • @user - I can confirm this. I had a similar (the same?) issue in the past and found that web application was running in 64-bit mode. The `InnerException` (which I require in a comment above) said "Bad Image Format Exception", which points to a 32-64 conflict. If you are using IIS you can define what mode to run your code in. If using Cassandra (and the same should hold for IIS Express, too) changing the compile mode to 32-bit x86 should suffice. However note that by that you might face bad-image issues with other libraries that you only have in 64bit versions. – chiccodoro Jun 10 '14 at 06:38
0

Another solution is to install both 32bit (x86) and 64bit (x64) Oracle client on your machine. Here is an instruction how to do this in order to make them working togeter: Install Oracle Client x86 and x64

Community
  • 1
  • 1
Wernfried Domscheit
  • 54,457
  • 9
  • 76
  • 110