Sap.Data.SQLAnywhere.SAException: Cannot find the language resource file (dblgen17.dll) when connecting to Sybase SQL Anywhere using .NET

0

I am trying to establish a connection to a Sybase database, using Sap.Data.SQLAnywhere. Using an SQL Anywhere client works perfect from a workstation, but I am having some trouble running the code within an Azure Function.

This is the beginning of my simple code:

using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using System.Data.SqlClient;
using Microsoft.Extensions.Logging;
using System;
using Sap.Data.SQLAnywhere;

namespace SBCTest
{
    public static class SybaseTest
    {
        static string DB_CS_SOURCE = "Host=myIP;UID=myUID;PWD=myPWD;Data Source=myDb;";         static int bulkSize = 5000;

        [FunctionName("SybaseTest")]
        public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequestMessage req, ILogger log)
        {
            try
            {
                var dbSourceCon = new SAConnection()
                dbSourceCon.ConnectionString = DB_CS_SOURCE;
                dbSourceCon.Open();

 //etc... etc...

The problem I am facing, which I can't seem to manage is the following error I get when running the app:

[Error] 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).
   at Sap.Data.SQLAnywhere.SAUnmanagedDll..ctor()
   at Sap.Data.SQLAnywhere.SAUnmanagedDll.get_Instance()
   at Sap.Data.SQLAnywhere.SAConnection..cctor()
   --- End of inner exception stack trace ---
   at Sap.Data.SQLAnywhere.SAConnection..ctor()
   at SBCTest.SybaseTest.<Run>d__3.MoveNext()

dblgen17.dll is included in the SAP SQL Anywhere Database Client found here, and has been added to my project, with Build Action set to None, and Copy to Output Directory set to Copy Always.

The "missing file" dblgen17.dll can be found in /site/wwwroot/bin after publish, as expected, along with Sap.Data.SQLAnywhere.v4.5.dll.

Why does it still say that it's missing? My Google results point me to the fact that it might have something to do with the PATH variable, but since this is an Azure Function I'm not sure what to do here. I also noted an additional, odd behavior, described below.

Sometimes, sporadically when re-publishing a non-altered code, I can also get this error message all of a sudden:

[Error] Sap.Data.SQLAnywhere.SAException (0x80004005)
at Sap.Data.SQLAnywhere.SAConnection.Open()
at SBCTest.SybaseTest.<Run>d__3.MoveNext()

How can I make my code recognize the file, and hopefully connect successfully?

sap
azure-functions
sybase
sqlanywhere
asked on Stack Overflow Apr 1, 2019 by swaglord mcmuffin' • edited Apr 1, 2019 by swaglord mcmuffin'

1 Answer

0

In my case, it worked out by reseting IIS, this can be done via cmd, with the iisreset command.

answered on Stack Overflow Feb 24, 2020 by Average Coder

User contributions licensed under CC BY-SA 3.0