dockerdockerfilehanasapb1sap-business-one-di-api

Connect to HANA database from docker container


I need to connect to SAP HANA database from docker container. It's asp net core web api project

I added those lines to my dockerfile:

# Create hdbclient directory and copy hdbclient folder to the container
RUN mkdir -p /usr/sap/hdbclient
COPY ../hdbclient /usr/sap/hdbclient

# Set HDBDOTNETCORE environment variable
ENV HDBDOTNETCORE /usr/sap/hdbclient/dotnetcore

without those lines it does not work when running on debug, but with those lines everything is okay. Probelem is that after publishing docker image hana connection does not work, there is no exception or anything execution just stops at this:

HanaConnection conn = new(connectionString);

and hangs there no errors no messages nothing.

What can it be? how can I even try to investigate it further?


Solution

  • I have the same issue running SapHana client connector for dotnet core 6 in linux container.

    I have downloaded the Sap.Data.Hana.Core.v2.1.dll and libadonetHDB.so from SAP official link: https://tools.hana.ondemand.com/#hanatools

    What I noticed in my cluster is that the first time the application start for around 5/10 minutes the job is employed to do some stuff when you invoke:

    using (HanaConnection hanaConnection = new HanaConnection(connectionString))
    { ... }
    

    I attach an image for demonstrating that CPU/Memory is busy in that period. After the first initialization, the connector will reply in some seconds without this issue.

    enter image description here

    If I use the libadonetHDB.dylib on my macOs this issue is not replicable.

    Seems to be an issue with the Linux library...

    FROM mcr.microsoft.com/dotnet/sdk:6.0 as build
    WORKDIR /app
    
    COPY *.sln .
    COPY MySolutionApi.Data/*.csproj ./MySolutionApi.Data/
    COPY MySolutionApi.Services/*.csproj ./MySolutionApi.Services/
    COPY MySolutionApi.WebApi/*.csproj ./MySolutionApi.WebApi/
    COPY nuget.config .
    COPY ["Sap.Data.Hana.Core.v2.1.dll", "./"]
    RUN dotnet restore
    
    # copy full solution over
    COPY . .
    RUN dotnet build
    
    # publish the API
    FROM build AS publish
    WORKDIR /app/MySolutionApi.WebApi
    RUN dotnet publish -c Release -o out
    
    FROM mcr.microsoft.com/dotnet/aspnet:6.0 as runtime
    WORKDIR /app
    COPY --from=publish /app/MySolutionApi.WebApi/out ./
    ENTRYPOINT [ "dotnet", "MySolutionApi.WebApi.dll" ]

    I inserted for simplicity my Sap.Data.Hana.Core dll inside the solution for building purpose. Then path for the linux libadonetHDB.so library is referenced as environment variable as following HDBDOTNETCORE = "/app/saplibs" where /app/saplibs is my volume mounted in my cluster.

    Hope this will help.

    Dave.