Cast exception when connecting to oracle

Cast exception when connecting to oracle

Postby vmakkenz » Thu 19 Nov 2009 12:30

Hi,

I get the following exception when trying to connect to oracle.

Exception message: Kan een object van het type System.String[] niet converteren naar het type System.String.
InnerException:
Exception occurred in: Devart.Data.Oracle
Exception thrown by: Devart.Data.Oracle.OracleHomeCollection a()
Stack trace:
bij Devart.Data.Oracle.OracleHomeCollection.a()
bij Devart.Data.Oracle.OracleInternalConnection..ctor(y connectionOptions, OracleInternalConnection proxyConnection)
bij Devart.Data.Oracle.bx.a(h A_0, Object A_1, DbConnectionBase A_2)
bij Devart.Common.DbConnectionFactory.a(DbConnectionPool A_0, h A_1)
bij Devart.Common.DbConnectionPoolGroup.c(DbConnectionPool A_0)
bij Devart.Common.DbConnectionPool.a()
bij Devart.Common.DbConnectionPool.GetObject()
bij Devart.Common.DbConnectionFactory.a(DbConnectionBase A_0)
bij Devart.Common.DbConnectionClosed.Open(DbConnectionBase outerConnection)
bij Devart.Common.DbConnectionBase.Open()
bij Devart.Data.Oracle.OracleConnection.Open()


I know the exception is in dutch but basically it says
Unable to cast object of type System.String[] to type System.String

I'm using version 5.0.20
vmakkenz
 
Posts: 18
Joined: Tue 26 Aug 2008 13:30

Postby Shalex » Fri 20 Nov 2009 11:51

1. Please post here your connection string.
2. How many Oracle clients do you have on your machine? Tell us their exact versions and installation types (Instant Client, Runtime, or Administrator).
3. Could you please try the latest 5.35.54 version of dotConnect for Oracle? Does the problem persist with the latest version as well?
Shalex
Devart Team
 
Posts: 7780
Joined: Thu 14 Aug 2008 12:44

Postby vmakkenz » Fri 20 Nov 2009 14:12

The connection string is faily simple, lots of our clients use it.
Its: Password=GVR;User ID=GVR;Data Source=STROOMLN

We can't use direct mode because we read/write blobs and geometries .

The way the oracle client is installed is out of our hands and not the way we normally see it. They got several oracle clients installed on a netwerk drive and installed the necessary registry keys on all local machines.

This works ok for all application excepts ours, I managed to reproduce the error locally on an virtual machine and got a reg file with all the keys they use.

I''l try to make a small app that uses the latest version to check if that solves the problem.
vmakkenz
 
Posts: 18
Joined: Tue 26 Aug 2008 13:30

Postby vmakkenz » Mon 23 Nov 2009 14:09

I did a small test with version: 5.25.44.0

The test code:
var oracleConnection1 = new OracleConnection();
oracleConnection1.Server = "STROOMLN";
oracleConnection1.UserId = "BASIS";
oracleConnection1.Password = "BASIS";

oracleConnection1.Open();
oracleConnection1.Close();

The error:
Zie het einde van dit bericht voor meer informatie over het aanroepen
van JIT-foutopsporing (Just In Time) in plaats van dit dialoogvenster.

************** Tekst van uitzondering **************
System.InvalidCastException: Kan een object van het type System.String[] niet converteren naar het type System.String.
bij Devart.Data.Oracle.OracleHomeCollection.a()
bij Devart.Data.Oracle.OracleInternalConnection..ctor(x connectionOptions, OracleInternalConnection proxyConnection)
bij Devart.Data.Oracle.b1.a(k A_0, Object A_1, DbConnectionBase A_2)
bij Devart.Common.DbConnectionFactory.a(DbConnectionPool A_0, k A_1)
bij Devart.Common.DbConnectionPoolGroup.c(DbConnectionPool A_0)
bij Devart.Common.DbConnectionPool.a()
bij Devart.Common.DbConnectionPool.GetObject()
bij Devart.Common.DbConnectionFactory.a(DbConnectionBase A_0)
bij Devart.Common.DbConnectionClosed.Open(DbConnectionBase outerConnection)
bij Devart.Common.DbConnectionBase.Open()
bij Devart.Data.Oracle.OracleConnection.Open()
bij CoreLabTest.Form1.button1_Click(Object sender, EventArgs e)
bij System.Windows.Forms.Control.OnClick(EventArgs e)
bij System.Windows.Forms.Button.OnClick(EventArgs e)
bij System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
bij System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
bij System.Windows.Forms.Control.WndProc(Message& m)
bij System.Windows.Forms.ButtonBase.WndProc(Message& m)
bij System.Windows.Forms.Button.WndProc(Message& m)
bij System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
bij System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
bij System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Geladen assembly's **************
mscorlib
Assembly-versie: 2.0.0.0
Win32-versie: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///c:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
CoreLabTest
Assembly-versie: 1.0.0.0
Win32-versie: 1.0.0.0
CodeBase: file:///C:/Documents%20and%20Settings/Gebruiker1/Bureaublad/CoreLabTest/CoreLabTest.exe
----------------------------------------
System.Windows.Forms
Assembly-versie: 2.0.0.0
Win32-versie: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
Assembly-versie: 2.0.0.0
Win32-versie: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
Assembly-versie: 2.0.0.0
Win32-versie: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
Devart.Data.Oracle
Assembly-versie: 5.25.44.0
Win32-versie: 5.25.44.0
CodeBase: file:///C:/Documents%20and%20Settings/Gebruiker1/Bureaublad/CoreLabTest/Devart.Data.Oracle.DLL
----------------------------------------
System.Data
Assembly-versie: 2.0.0.0
Win32-versie: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.Data/2.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
System.Transactions
Assembly-versie: 2.0.0.0
Win32-versie: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.Transactions/2.0.0.0__b77a5c561934e089/System.Transactions.dll
----------------------------------------
Devart.Data
Assembly-versie: 5.0.8.0
Win32-versie: 5.0.8.0
CodeBase: file:///C:/Documents%20and%20Settings/Gebruiker1/Bureaublad/CoreLabTest/Devart.Data.DLL
----------------------------------------
System.Xml
Assembly-versie: 2.0.0.0
Win32-versie: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
mscorlib.resources
Assembly-versie: 2.0.0.0
Win32-versie: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///c:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
System.Windows.Forms.resources
Assembly-versie: 2.0.0.0
Win32-versie: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms.resources/2.0.0.0_nl_b77a5c561934e089/System.Windows.Forms.resources.dll
----------------------------------------

************** JIT-foutopsporing **************
Als u JIT-foutopsporing wilt inschakelen, moet in het configuratiebestand voor deze
toepassing of computer (machine.config) de waarde
jitDebugging in het gedeelte system.windows.forms zijn ingesteld.
De toepassing moet ook zijn gecompileerd terwijl foutopsporing
was ingeschakeld.

Bijvoorbeeld:





Wanneer JIT-foutopsporing is ingeschakeld, worden onverwerkte uitzonderingen
naar het JIT-foutopsporingsprogramma gestuurd dat op de computer is geregistreerd
en worden niet door dit dialoogvenster verwerkt.
vmakkenz
 
Posts: 18
Joined: Tue 26 Aug 2008 13:30

Postby Shalex » Tue 24 Nov 2009 10:49

Please run this function in any of your applications and send us the results. This function should return the error on your machine. It works fine in our environment, and we don't know the possible situation when this error arises. So, please give us the following information according this test:
1) on what line of this code are you getting the error (run it in the debug mode)?
2) what is the exact string[] value converted to string?
Code: Select all
    private string GetHomes() {

      StringBuilder sb = new StringBuilder();

      RegistryKey allHomes =
Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\ORACLE\ALL_HOMES");
      ArrayList singleInstance = new ArrayList();
      // add Oracle clients <10g to singleInstance
      // Oracle 10g dose not has ALL_HOMES key
      if (allHomes != null) {
        foreach (string id in allHomes.GetSubKeyNames()) {
          RegistryKey idKey = allHomes.OpenSubKey(id);
          Microsoft.Win32.RegistryKey homeKey =
            Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\ORACLE\HOME"
+ id.Substring(2));
          string tnsAdmin;
          if (homeKey != null) {
            tnsAdmin = (string)homeKey.GetValue("TNS_ADMIN");
            homeKey.Close();
          }
          else
            tnsAdmin = "";

          sb.Append("\r\n\r\nName=");
          sb.Append((string)idKey.GetValue("NAME"));
          sb.Append("\r\nNLS_LANG=");
          sb.Append((string)idKey.GetValue("NLS_LANG"));
          sb.Append("\r\nPATH=");
          sb.Append((string)idKey.GetValue("PATH"));
          sb.Append("\r\nTNS_ADMIN=");
          sb.Append(tnsAdmin);
          singleInstance.Add((string)idKey.GetValue("PATH"));
        }
        allHomes.Close();
      }

      // add Oracle clients >=10g to singleInstance
      RegistryKey allOracleKeys =
Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\ORACLE");
      if (allOracleKeys != null) {
        foreach (string id in allOracleKeys.GetSubKeyNames()) {
          if (id.StartsWith("KEY_")) {
            RegistryKey idKey = allOracleKeys.OpenSubKey(id);
            string name = (string)idKey.GetValue("ORACLE_HOME_NAME");
            string nlsName = (string)idKey.GetValue("NLS_LANG");
            string homePath = (string)idKey.GetValue("ORACLE_HOME");
            string tnsAdmin = (string)idKey.GetValue("TNS_ADMIN");
            if (homePath != null && homePath != "") {
              sb.Append("\r\n\r\nName=");
              sb.Append(name);
              sb.Append("\r\nNLS_LANG=");
              sb.Append(nlsName);
              sb.Append("\r\nPATH=");
              sb.Append(homePath);
              sb.Append("\r\nTNS_ADMIN=");
              sb.Append(tnsAdmin);
              singleInstance.Add(homePath);
            }
          }
        }
        allOracleKeys.Close();
      }

      // check if defaultHome as the first dir with oci.dll
      string path = Environment.GetEnvironmentVariable("PATH");
      string[] envPaths = path.Split(';');

      for (int i = 0; i < envPaths.Length; i++) {
        try {
          if (File.Exists(Path.Combine(envPaths[i], "Oci.dll"))) {
            for (int j = 0; j < singleInstance.Count; j++) {
              if (envPaths[i] == null || envPaths[i] == "")
                continue;
              if (String.Compare(envPaths[i],
Path.Combine((string)singleInstance[j], "bin"), true,
System.Globalization.CultureInfo.InvariantCulture) == 0) {
                return sb.ToString();
              }
              if (String.Compare(envPaths[i], (string)singleInstance[j],
true, System.Globalization.CultureInfo.InvariantCulture) == 0) {
                return sb.ToString();
              }
            }
            sb.Append("\r\n\r\nName=\r\nNLS_LANG=\r\nPATH=");
            sb.Append(envPaths[i]);
            sb.Append("\r\nTNS_ADMIN=");
            return sb.ToString();
          }
        }
        catch {
        }
      }
      return sb.ToString();
    }
Shalex
Devart Team
 
Posts: 7780
Joined: Thu 14 Aug 2008 12:44

Postby vmakkenz » Tue 24 Nov 2009 12:03

Thanks for the code, the line where the exception occured was:

string tnsAdmin = (string)idKey.GetValue("TNS_ADMIN");

Turns out that that TNS_ADMIN was of type REG_MULTI_SZ which leads to an string array return in GetValue.

I have no idea why they got a multi string in the registry, but we know the reason for the crash and we can fix the registry.

Thank you.
vmakkenz
 
Posts: 18
Joined: Tue 26 Aug 2008 13:30


Return to dotConnect for Oracle