Global Data Management Forum

 View Only
Expand all | Collapse all

Issues Connecting DB2 from an Azure Function app(.Net core 3.1) using IBM.Data.DB2.Core (1.3.0.100)

  • 1.  Issues Connecting DB2 from an Azure Function app(.Net core 3.1) using IBM.Data.DB2.Core (1.3.0.100)

    Posted Tue November 09, 2021 04:50 PM
    Hello @Hosathota Vishwanatha, i have read your blog on how to connect to DB2 from an Azure function app, everything is clear but i am getting an error " Length cannot be less than zero. (Parameter 'length')." can you please help me on this.

    i am trying to develop a time triggered function app , here is the code wrote, but i am getting that error while "connection.Open();"

    public static class Function1
    {
    [FunctionName("Function1")]
    public static void Run([TimerTrigger("0 */5 * * * *")] TimerInfo myTimer, ILogger log)
    {
    try
    {
    log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");


    string responseMessage = "This Time triggered function executed successfully. Welcome ";
    responseMessage += " DB open will be tried ";
    DB2Connection connection = new DB2Connection("Server = ************** :***; Database = ********** ; UID = ****** ; PWD = *********; ");

    // string version = connection.ServerVersion;
    connection.Open();
    responseMessage += " DB opened" + connection.ServerVersion;
    Console.WriteLine(responseMessage);
    connection.Close();
    }
    catch (Exception ex)
    {
    string responseMessage = null;
    responseMessage += " Db error " + ex.Message;
    // return new Microsoft.AspNetCore.Mvc.OkObjectResult(responseMessage);

    }
    }

    } ​

    Can you please help me on this?

    thanks.

    ------------------------------
    Vamshider Dasari
    ------------------------------

    #DataManagementGlobal
    #DataServerDrivers


  • 2.  RE: Issues Connecting DB2 from an Azure Function app(.Net core 3.1) using IBM.Data.DB2.Core (1.3.0.100)

    Posted Wed November 10, 2021 03:50 AM
    Hi,
     we have not seen this issue earlier and we will check and get back to you. Meanwhile, you may want to check if the same connection string works from a simple console application.

    Thanks
    Vishwa

    ------------------------------
    Hosathota Vishwanatha
    ------------------------------



  • 3.  RE: Issues Connecting DB2 from an Azure Function app(.Net core 3.1) using IBM.Data.DB2.Core (1.3.0.100)

    Posted Wed November 10, 2021 08:40 AM
    Thanks @Hosathota Vishwanatha, for the reply. 
    Yes i have tried to with a normal console app and it works fine. please refer the screen shots below
    CODE CONNECTING AZURE DB2
    CODE CONNECTING CONSOLE APP DB2


    ------------------------------
    Vamshider Dasari
    ------------------------------



  • 4.  RE: Issues Connecting DB2 from an Azure Function app(.Net core 3.1) using IBM.Data.DB2.Core (1.3.0.100)

    Posted Fri November 12, 2021 01:31 AM
    Hi Vamshider,
     one thing which is confusing is the package version you are mentioning. Its mentioned as 1.3.0.100. Can you please use the latest version of .NET Core 3.1 which is version 3.1.0.500 (https://www.nuget.org/packages/IBM.Data.DB2.Core)? Since the latest versions will have cumulative fixes, we recommend to use the latest versions of .NET Core packages.

    I also notice that using statement is not there(Using IBM.Data.Db2.Core) in the first screen you shared. I am wondering whether it compiles at all.

    Thanks
    Vishwa

    ------------------------------
    Hosathota Vishwanatha
    ------------------------------