Found this gem recently: NTi Data Provider - sharing my feedback
I think it's worth sharing here as I was recently looking for a way to call AS400 programs from .NET (see my question here) and came across Aumerial.Data.Nti nuget package.
It worked great for my initial use case, and it also provides access to DB2 for i database with standard ADO.NET and also EF Core. It's very easy and convenient to use, and it's fully standalone, ie just the package to donwload, nothing to install on the client side (no driver) + nothing to install on the AS400 as well. It works on .NET Framework as well as .NET Core environments.
Here are some examples of how I implemented it successfully :
Database query using plain ADO.NET
var connectionString = "server=....;user=....;password=....;";
using (var conn = new NTiConnection(connectionString)) {
conn.Open();
var cmd = conn.CreateCommand();
cmd.CommandText = "UPDATE LIB.CUSTOMERS SET NAME = ? WHERE ID = ?";
cmd.DeriveParameters();
cmd.Parameters[0].Value = "Martin";
cmd.Parameters[1].Value = 10;
conn.ExecuteNonQuery();
}
Database query using Dapper
var cust = new Customer() {Id = 10};
using (var conn = new NTiConnection(connectionString)) {
var data = conn.Query<Customer>("SELECT * FROM LIB.CUSTOMERS WHERE ID = @ID", cust);
}
Database query using EF Core
Register NTi as you'd do for other DBMS, e.g. :
builder.Services.AddDbContext<ApplicationDbContext>(
options => options.UseNTi(connectionString)
);
Executing CL Commands:
using (var conn = new NTiConnection(connectionString)) {
conn.Open();
conn.ExecuteClCommand("DLTLIB TEMPLIB");
}
Calling program:
Why I used NTi at first, here is a complex use case where I needed to convert POCOs to program parameter and then parse the returned data back to POCO:
//Employee instance (POCO)
var empl = new Employee() {
Name = "Foo",
Salary = 50000.0M
};
//Opening the connection
var conn = new NTiConnection(connectionString);
conn.Open();
//Creating the parameter according to the datastructure
var parms = new List<NTiProgramParameter>() {
new NTiProgramParameter(empl.Name, 10).Append(empl.Salary, 9, 2)
};
//Program call
conn.CallProgram("PGMLIB", "EMPLPGM", parms);
//Retreive returned data from the DS to the POCO
empl.Name = parms[0].GetString(0, 10); //0 offset, 10 in length
empl.Salary = parms[0].GetPackedDecimal(9, 2, 10); //PACKED(9, 2), 10 offset
Getting a license key
It is a 3rd party solution from AUMERIAL, as I understood they work closely with IBM. I contacted them directly from their website and obtained a free trial key in just a few hours, they provided me with an SQL script to run on the AS400 and then everything was ready in like 10 seconds.
Hope it can help someone trying to connect to AS400 using .NET as it did for me :)