cancel
Showing results for 
Search instead for 
Did you mean: 

Store dblgde17.dll and dblgen17.dll in different directory (ADO.NET)

1,997

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!

chris_keating
Product and Topic Expert
Product and Topic Expert
0 Kudos

You did not indicate the specific patch level for SQLA17. This is likely Engineering Case #819001 which revises the file search algorithm. Please review the details in the Readme notes for SA 17 Build 5787 or newer.

0 Kudos

Thanks for the fast reply. I'm using 17.0.10.63154 (ADO.Net) and 17.0.10.6315 (dblgde17)

Accepted Solutions (1)

Accepted Solutions (1)

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}");
}

Answers (0)