6 Replies Latest reply: Aug 6, 2013 6:45 AM by 810804 RSS

    Error: System.TypeInitializationException

    544953
      I'm running Visual Studio 2008 on Windows XP, connecting to a 10g R2 database on Windows Server 2003.

      I'm getting the following error when attempting to run a .Net stored procedure:

      ORA-20100: System.TypeInitializationException
      The type initializer for 'Oracle.DataAccess.Client.OracleConnection' threw and exception.
      at Oracle.DataAccess.Client.OracleConnection..ctor()
      at MyStoredProcedure.Test.GetCountChemistryId(Int32 chemistry_id)
      ORA-06512: at "SYS.DBMS_CLR", line 152
      ORA-06512: at "CASEY.GETCOUNTCHEMISTRYID", line 7

      The code looks like the following:

      using System.Collections.Generic;
      using System.Text;
      using System.Data;
      using Oracle.DataAccess.Client;
      using Oracle.DataAccess.Types;

      namespace MyStoredProcedure
      {
      public class Test
      {
      public static int GetCountChemistryId(int chemistry_id)
      {
      int val = 0;
      OracleConnection con = new OracleConnection();
      con.ConnectionString = "context connection=true";
      con.Open();

      OracleCommand cmd = con.CreateCommand();
      cmd.CommandText = "select count(chemistry_id) from chemistry_exp_activity where chemistry_id = :1";
      cmd.Parameters.Add(":1", OracleDbType.Int32, chemistry_id, ParameterDirection.Input);
      OracleDataReader reader = cmd.ExecuteReader();
      reader.Read();
      val = reader.GetInt32(0);
      reader.Close();
      cmd.Dispose();

      return val;
      }
      }
      }

      I've written this procedure as a test. It's my first attempt at using .Net stored procedures.

      I have deployed the procedure successfully, but I cannot call it from any client without generating the above System.TypeInitializationException error.

      Also, I should mention that when I first attempted to deploy the procedure I was greeted with
      ORA-20100: System.IO.FileNotFoundException. File or assembly name Oracle.DataAccess, or one of its dependencies, was not found.'

      I resolved this error by making sure the Oracle Deployment Wizard copied all the relevant project dlls to my <oraclehome>bin/clr directory, but I'm wondering if it might not be related to my current issue.