It is a common scenario where in many of the existing IBM i Access for Windows .NET provider applications are migrated to Db2Connect .NET provider. This article lists down the points to consider while doing so and changes which are needed at various levels.
One of the reasons why many applications are getting migrated is, Db2Connect .NET Provider supports multiple platform support through NuGet packages. Also, Db2Connect providers features such Entity Framework support, easy cloud deployment etc.
There are factors consider while migrating from IBM i Access to Db2Connect .NET provider:
Db2Connect -
- is up-to-date with Microsoft .NET Technology support including latest .NET 9 support.
- provides multi-platform support.
- supports modern deployments such MS Azure, AWS and RedHat OpenShift
- is a licensed product and requires a license to connect to IBM Data Servers.
- uses DRDA based protocol and requires certain port to be enabled on IBM i.
- provides multiple support paths including regular upgrades based on technology change.
It is advisable to start with a trial license and this trial license file can be requested through NuGet package messaging. If there is already a Db2Connect license, then no additional license file is not needed. The application can be developed targeting Windows, Linux, Mac, Linux on IBM Z and ppc64le.
Let's go through a simple console application to be deployed on Windows. This example uses Visual Studio 2022 as the IDE and uses Db2 .NET 8 latest package to create a sample Console application.
Step1 : Open Visual Studio 2022 (VS2022) and start with 'Create New Project' option:

Click Next option in the above screen after selecting Console App as the Project Template.
Step 2: Provide a name to the project. Example below uses IBMiConnect as the project name.

Choose appropriate location for the project and click Next
Step 3: Choose the target framework and whether Docker support is needed. This example excludes Docker support

Click on "Create"
Step 4: A Hello World default console application is created and change the configuration to x64

Step 5: To add reference to Db2 .NET NuGet package, use the Package Manager option

and search for "Net.IBM.Data.Db2"

Since search lists the latest version but we are planning to use the last LTS (Long Term Support), lets change the version to 8.* latest version.

Use the Install option next to the package version and accept the terms and conditions to install the latest Db2 .NET 8 package into this application
Note: Please choose the target specific packages. The example uses Windows deployment hence package without any suffix is selected. For Linux use package with -lnx, use -osx for Mac, -zlnx for Linux on IBM Z or -ppcl for ppc64le. |

Note: Once the package is added to the Project, a virtual folder 'clidriver' is added to the project which will be referenced later on. |
Step 6: Next step is to add code using Db2 ,NET code to access IBM i Server. The example just opens a connection and prints the Server Version.
using IBM.Data.Db2;
namespace IBMiConnect { internal class Program { static void Main(string[] args) { try {
DB2Connection connection = new DB2Connection("Server=<dataserver>:446; uid=<userid>; pwd=<passwordtoconnect>; database=<mydatabasename>"); connection.Open(); Console.WriteLine("DB2 Connection has opened Successfully with Server : " + connection.ServerVersion); } catch (Exception ex) { Console.WriteLine("There is some issue in opening the connection : " + ex.ToString()); }
} } }
|
In the above code, a valid connection string needs to be provided which includes a dataserver hostname or IP address, port number, user id, password and database name.
Note: Many a times, it is noticed that the port number provided above (446 in the example) is either not exposed or not correctly configured to access from outside. This results in failed connection attempt with a TCP error. |
Step 7: Before executing the above code, we have to make sure a valid Db2Connect license is available. Db2Connection provides multiple licensing options depending on the need. For the example above, we use a client-side trial license
Navigate to the application bin folder using 'Open Folder in File Explorer' option.

If a trial license is available, place the license file in the above folder. If a trial license is needed, please use the contact owner option of the NuGet repository

Incase if the license is activated at the server already, then neither the trial license is needed nor copying any license file as explained in the step 7 is needed.
To understand more about activating the license at data server, please refer to below link
https://www.ibm.com/docs/en/db2/11.5?topic=edition-db2connectactivate-server-license-activation-utility
With all the above settings, now we can compile and execute the application, and in the output, we should be able to see the version of the IBM i Data Server.
Related links:
Using Stored Procedure with Db2 .NET NuGet packages
https://community.ibm.com/community/user/datamanagement/blogs/tapan-ghosh1/2021/05/07/calling-external-stored-procedure-on-db2-for-i-usi
List of Db2 .NET driver connection strings
DB2ConnectionStringBuilder members - IBM Documentation
IBM i ports (with particular interest to DRDA port)
https://www.ibm.com/support/pages/tcpip-ports-required-ibm-i-access-and-related-functions
List of Db2Dotnet NuGet packages
NuGet Gallery | IBMDB2EF
Capturing db2trace with Db2 .NET NuGet package drivers
https://community.ibm.com/community/user/datamanagement/blogs/naveenkumar-n-l2/2021/07/27/steps-to-create-traces-for-different-db2-net-provi