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!

asked 07 Sep, 12:01

benedikteggers's gravatar image

benedikteggers
414
accept rate: 100%

edited 07 Sep, 15:03

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.

(07 Sep, 13:40) Chris Keating

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

(07 Sep, 13:56) benedikteggers

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

answered 07 Sep, 18:33

benedikteggers's gravatar image

benedikteggers
414
accept rate: 100%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×191
×68
×37

question asked: 07 Sep, 12:01

question was seen: 89 times

last updated: 07 Sep, 18:33