on 2021 Sep 07 1:01 PM
We are migrating from Sybase SQL Anywhere 12 to 17. In the root directory of our application the Sap.Data.SQLAnywhere.EF6.dll is located. Furthermore, in this directory, we have a bin32 and bin64 directory containing the native sybase dll (e.g. dblgde17.dll and dblgen17.dll). When we now start our application, we add those directories to the env, to ensure they will be used for loading the dlls:
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] static extern bool SetDllDirectory(string lpPathName); [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] static extern bool AddDllDirectory(string lpPathName);
And
var platform = Environment.Is64BitOperatingSystem ? "bin64" : "bin32"; try { AddDllDirectory(GlobalSettings.StudioPath + $"\\\\{platform}"); } catch { SetDllDirectory(GlobalSettings.StudioPath + $"\\\\{platform}"); }
This worked pretty well with sybase 12 and 16, but when migrating to sybase 17, the dlls will not be found/loaded. So there must be any change in the behaviour of the component, is that right?
Actual error message: System.TypeInitializationException: The type initializer for 'Sap.Data.SQLAnywhere.SAConnection' threw an exception. ---> Sap.Data.SQLAnywhere.SAException: Cannot find the language resource file (dblgen17.dll).
Hint: When adding the bin64 directory to the PATH env-var, it is working. But this will cause some other problems, so it is not a solution for us.
How can we fix this problem?
EDIT
Setting the path in the application does not help either:
var saPath = Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Machine) ?? ""; Console.WriteLine($"Existing SA-Path {saPath}"); if (string.IsNullOrWhiteSpace(saPath) || !saPath.Contains(GlobalSettings.StudioPath)) { if (saPath.Any() && !saPath.EndsWith(";")) saPath += ";"; saPath += $"{GlobalSettings.StudioPath}\\\\bin32\\\\;{GlobalSettings.StudioPath}\\\\bin64\\\\"; Environment.SetEnvironmentVariable("PATH", saPath, EnvironmentVariableTarget.Machine); Console.WriteLine($"New SA-Path {saPath}"); }
Thanks a lot!
This seems to solve the issue. Those lines of code must be called at the beginning of the application
var envPath = Environment.GetEnvironmentVariable("PATH") ?? ""; var platform = Environment.Is64BitOperatingSystem ? "bin64" : "bin32"; var bonPath = $"{GlobalSettings.StudioPath}\\\\{platform}\\\\"; if (string.IsNullOrWhiteSpace(envPath) || !envPath.Contains(bonPath)) { if (envPath.Any() && !envPath.EndsWith(";")) envPath += ";"; Environment.SetEnvironmentVariable("PATH", $"{envPath}{bonPath}"); }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
69 | |
9 | |
8 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.