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?
Cast exception when connecting to oracle
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?
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
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();
}