Global Data Management Forum

 View Only
Expand all | Collapse all

Connecting to IBM i with C sharp on .NET 7 (old version called .NET Core)

  • 1.  Connecting to IBM i with C sharp on .NET 7 (old version called .NET Core)

    Posted Fri June 23, 2023 01:33 PM

    Hi IBM DB2 Team,

    My applications work fine on .NET Framework 4.8 with IBM.Date.DB2.iSeries.dll from IBM i Access Client Solutions.

    i am trying to migrate my applications from .NET Framework 4.8 to .NET 7.

    here is my environment:

    IBM i: V7.4

    .NET 7

    Windows 2016 server

    visual studio 2022 (C sharp)

    i created a simple console application in VS on .NET 7 and installed Net.IBM.Data.Db2 (7.0.0.200).

    Here is my code:

    using System.Data.Common;
    using System.Data;
    using IBM.Data.Db2;

    using (DB2Connection iDB2Conn = new DB2Connection("Server=IP_ADDRESS;database=Databasename;UserID=DUMMY;Password=DUMMY;"))
    using (DB2Command iDB2Cmd = new DB2Command())
    {

        iDB2Conn.Open();
        iDB2Cmd.Connection = iDB2Conn;

    }

    Here is the error message:

    IBM.Data.Db2.DB2Exception
      HResult=0x80004005
      Message=External component has thrown an exception.
      Source=IBM.Data.Db2
      StackTrace:
       at IBM.Data.Db2.DB2ConnPool.Open(DB2Connection connection, String& szConnectionString, DB2ConnSettings& ppSettings, Object& ppConn)
       at IBM.Data.Db2.DB2Connection.Open()
       at Program.<Main>$(String[] args) in C:\TestProject\ApiTest\ApiTest\Program.cs:line 13

    Could anybody shed light on this issue?

    i appreciate any help!

    Bruce



    ------------------------------
    Bruce Ma
    ------------------------------


  • 2.  RE: Connecting to IBM i with C sharp on .NET 7 (old version called .NET Core)

    Posted Fri June 23, 2023 02:18 PM

    I'm connecting to an Informix db w/ entity framework... 

    comparing your connection string, we have a space in 'User ID='...  User<SPACE>ID=....
    we also have a port  in the Server=address:port ... maybe its default and yours aren't the same

    I've seen other posts/issues on here about licenses... 



    ------------------------------
    John Robinson
    ------------------------------



  • 3.  RE: Connecting to IBM i with C sharp on .NET 7 (old version called .NET Core)

    Posted Fri June 23, 2023 03:22 PM

    Hi John,

    thank you for your quick response. i tried your suggestion and changed the connection string from UserID to User ID and added port number 446. it was still the same error with or without port number.

    this error seems not reach license issue yet.

    Do you have any advice?

    Thank you,

    Bruce



    ------------------------------
    Bruce Ma
    ------------------------------



  • 4.  RE: Connecting to IBM i with C sharp on .NET 7 (old version called .NET Core)

    Posted Fri June 23, 2023 03:47 PM

    Afraid not. Try Entity Framework? 

    https://stackoverflow.com/questions/62880235/ibm-data-db2-core-setup-procedure

    Since my test app doesnt have dependency injection, it news up a dbcontext like:


    var optionsBuilder = new DbContextOptionsBuilder<MyDBContext>();
    optionsBuilder.UseDb2(connectionString, d => d.SetServerInfo(IBMDBServerType.YOURTYPE, IBMDBServerVersion.YOURVERSION));
    var ecfDbContext = new MyDBContext(optionsBuilder.Options);
     dbcontext:
    public
    partial class MyDBContext : DbContext
        {
            public DbSet<TableClass> Table { get; set; }

            public MyDBContext(DbContextOptions<MyDBContext> options)
                : base(options)
            {
            }
        }


    ------------------------------
    John Robinson
    ------------------------------



  • 5.  RE: Connecting to IBM i with C sharp on .NET 7 (old version called .NET Core)

    Posted Fri June 23, 2023 06:00 PM

    Hi John,

    what do you mean by  "Afraid not"?

    Do you mean that it is not impossible to connect to IBM i db2 with Net.IBM.Data.Db2 (7.0.0.200)?

    the site you provided seems not using IBM.EntityFrameworkCore.

    the example on the site is based on .NET Core 3.1 which is supported anymore.

    Can you please give me an example with detailed information?

    Thank you so much,

    Bruce



    ------------------------------
    Bruce Ma
    ------------------------------



  • 6.  RE: Connecting to IBM i with C sharp on .NET 7 (old version called .NET Core)

    Posted Fri June 23, 2023 06:10 PM

    Afraid not meaning I don't have any more advice...

    The above lines worked in .net core 6... 

    As I don't work for IBM, you'll have to find better examples on the web for DB2. 



    ------------------------------
    John Robinson
    ------------------------------



  • 7.  RE: Connecting to IBM i with C sharp on .NET 7 (old version called .NET Core)

    Posted Fri June 23, 2023 06:22 PM

    Hi John,

    Did i post my question on the correct website?

    if not, can you please give me a link of the right site?

    You are the first person to pick up my question and then you told me don't know IBM. Could you please let me know who i should look for?

    Thanks anyway,

    Bruce



    ------------------------------
    Bruce Ma
    ------------------------------



  • 8.  RE: Connecting to IBM i with C sharp on .NET 7 (old version called .NET Core)

    Posted Mon June 26, 2023 11:01 AM
    here are a few steps you can try:
     
    Ensure that you have the necessary dependencies installed: Make sure you have the IBM i Access Client Solutions installed on your Windows 2016 server. This client package includes the required drivers and libraries for connecting to IBM DB2.
     
    Verify the connection parameters: Double-check that the connection parameters (server IP address, database name, username, and password) you provided are correct and valid for your IBM DB2 instance. Ensure that you have the appropriate permissions to access the database.
     
    Check the compatibility of the IBM.Data.Db2 library: Confirm that the version of the IBM.Data.Db2 library you're using (7.0.0.200) is compatible with the .NET 7 framework. It's possible that the library may not fully support the latest version of .NET, which could lead to compatibility issues.
     
    Review the documentation and examples: Consult the official IBM.Data.Db2 documentation and any available code examples to ensure you're using the library correctly. Pay attention to any specific requirements or configurations needed when using the library with .NET 7.
     
    Enable detailed error logging: Modify your code to catch and log any inner exceptions that might provide more specific information about the error. This can help in diagnosing the root cause of the problem.


    ------------------------------
    Selin Moran
    ------------------------------



  • 9.  RE: Connecting to IBM i with C sharp on .NET 7 (old version called .NET Core)

    Posted Mon June 26, 2023 12:00 PM

    Hi Selin,

    First of all, thank you for your suggestion. Please see my comments for you steps.

    1. why do i still need to install IBM i Access Client Solutions. actually i have it installed, buy i don't know the reason if i install Net.IBM.Data.Db2 from NuGet.
    2. The parameters are correct and the user has the appropriate permissions to access the database.
    3. Net.IBM.Data.Db2 is IBM's production, i think you should be able to tell me whether or not it is compatible with .NET 7.
    4. You let me review the document. yes, this is correct, but it is too unspecific. please advise me some specific information.
    5. i did put try and catch in my code, but i debugged the program. i already put the error message on my post.

    Please advise,

    Bruce



    ------------------------------
    Bruce Ma
    ------------------------------



  • 10.  RE: Connecting to IBM i with C sharp on .NET 7 (old version called .NET Core)

    Posted Mon June 26, 2023 12:35 PM

    Hello everyone,

    I cannot login into my IBM community account, why? Why is happening this? It took me one day to set up a new account and start contributing with valid answers to the persons that were in need. I need your help. Thank you

    On 26/06/2023 18:02, Bruce Ma via IBM TechXchange Community wrote:
    01000188f870cde9-19a9a151-4358-4094-845c-b89d1de2e760-000000@email.amazonses.com">
    Hi Selin, First of all, thank you for your suggestion. Please see my comments for you steps. why do i still need to install IBM i Access... -posted to the "Data Management Global" group
    IBM TechXchange Community

    Global Data Management Forum

    Post New Message
    Re: Connecting to IBM i with C sharp on .NET 7 (old version called .NET Core)
    Reply to Group Reply to Sender
    Bruce Ma
    Jun 26, 2023 12:00 PM
    Bruce Ma

    Hi Selin,

    First of all, thank you for your suggestion. Please see my comments for you steps.

    1. why do i still need to install IBM i Access Client Solutions. actually i have it installed, buy i don't know the reason if i install Net.IBM.Data.Db2 from NuGet.
    2. The parameters are correct and the user has the appropriate permissions to access the database.
    3. Net.IBM.Data.Db2 is IBM's production, i think you should be able to tell me whether or not it is compatible with .NET 7.
    4. You let me review the document. yes, this is correct, but it is too unspecific. please advise me some specific information.
    5. i did put try and catch in my code, but i debugged the program. i already put the error message on my post.

    Please advise,

    Bruce



    ------------------------------
    Bruce Ma
    ------------------------------
      Reply to Group Online   View Thread   Recommend   Forward   Flag as Inappropriate  




     
    You are receiving this notification because you followed the 'Connecting to IBM i with C sharp on .NET 7 (old version called .NET Core)' message thread. If you do not wish to follow this, please click here.

    Update your email preferences to choose the types of email you receive

    Unsubscribe from all participation emails




    Original Message:
    Sent: 6/26/2023 12:00:00 PM
    From: Bruce Ma
    Subject: RE: Connecting to IBM i with C sharp on .NET 7 (old version called .NET Core)

    Hi Selin,

    First of all, thank you for your suggestion. Please see my comments for you steps.

    1. why do i still need to install IBM i Access Client Solutions. actually i have it installed, buy i don't know the reason if i install Net.IBM.Data.Db2 from NuGet.
    2. The parameters are correct and the user has the appropriate permissions to access the database.
    3. Net.IBM.Data.Db2 is IBM's production, i think you should be able to tell me whether or not it is compatible with .NET 7.
    4. You let me review the document. yes, this is correct, but it is too unspecific. please advise me some specific information.
    5. i did put try and catch in my code, but i debugged the program. i already put the error message on my post.

    Please advise,

    Bruce



    ------------------------------
    Bruce Ma
    ------------------------------

    Original Message:
    Sent: Fri June 23, 2023 03:54 PM
    From: Selin Moran
    Subject: Connecting to IBM i with C sharp on .NET 7 (old version called .NET Core)

    here are a few steps you can try:
     
    Ensure that you have the necessary dependencies installed: Make sure you have the IBM i Access Client Solutions installed on your Windows 2016 server. This client package includes the required drivers and libraries for connecting to IBM DB2.
     
    Verify the connection parameters: Double-check that the connection parameters (server IP address, database name, username, and password) you provided are correct and valid for your IBM DB2 instance. Ensure that you have the appropriate permissions to access the database.
     
    Check the compatibility of the IBM.Data.Db2 library: Confirm that the version of the IBM.Data.Db2 library you're using (7.0.0.200) is compatible with the .NET 7 framework. It's possible that the library may not fully support the latest version of .NET, which could lead to compatibility issues.
     
    Review the documentation and examples: Consult the official IBM.Data.Db2 documentation and any available code examples to ensure you're using the library correctly. Pay attention to any specific requirements or configurations needed when using the library with .NET 7.
     
    Enable detailed error logging: Modify your code to catch and log any inner exceptions that might provide more specific information about the error. This can help in diagnosing the root cause of the problem.


    ------------------------------
    Selin Moran


  • 11.  RE: Connecting to IBM i with C sharp on .NET 7 (old version called .NET Core)

    Posted Tue July 04, 2023 02:35 PM

    Hi Selin,

    are you able to sign into IBM community account?

    Thanks,

    Bruce



    ------------------------------
    Bruce Ma
    ------------------------------