NTiConnection Class.

Description.

The NTiConnection class represents the connection to the IBM i and implements the DbConnection class from the ADO.NET model (System.Data.Common namespace).

General considerations.

Connection Pool.

Starting with version 3.2.3, NTi implements a .NET-based connection pool, ensuring rigorous tracking of open connections and preventing the excessive creation of QZDASOINIT jobs.

Opening a connection to the IBM i involves several costly operations: IP resolution, TCP negotiation, authentication, and job creation on the IBM i. Repeating these operations for every request significantly impacts performance.

The NTi pooling mechanism works as follows:

  • When a connection is requested, NTi first checks the pool for an available connection. If one is found, it is reused immediately; otherwise, a new connection is created and added to the pool.
  • When the connection is no longer in use, it is returned to the pool instead of being closed.
  • When the application stops or the pool is destroyed, all connections are properly closed.

Pooling is enabled by default starting with NTi 3.2.3. It can be disabled if manual control of connections is required.

💡 Observed benefits: response time reduced from 80ms to 6ms, delivering more than a 10x performance gain in some use cases (particularly with Entity Framework Core).

Multi-Factor Authentication (MFA)

MFA (Multi-Factor Authentication) is a security mechanism introduced by IBM in the latest IBM i releases (V7R6+). It's based on the generation of a one-time password (OTP) through a TOTP (Time-based One-Time Password) compatible application (e.g. Microsoft Authenticator).

When signing in, this code is required in addition to the regular password to strengthen access protection. Since version 4.4.0, NTi supports this mechanism and allows the OTP code to be provided in two ways:

  • with a callback AdditionalFactorCallback, triggering an interactive user prompt.
  • with the property AdditionalFactor, where the code is passed directly.

Reminder: Enabling MFA on IBM i (starting with V7R6).

1. System prerequisites:

  • QSECURITY = 40 or 50
  • QPWDLVL = 4

2. Enable MFA system-wide:

 CHGSECA ADLSGNFAC(*ENABLED)

💡 An IPL is required after this command to apply the changes.

3. Configure MFA per user:

From the user profile:

  • Generate a TOTP key for the profile:
CHGTOTPKEY USRPRF() KEY(*GEN)
  • Copy the key into the personal MFA application (e.g., Microsoft Authenticator) and securely store the recovery keys.
  • Apply MFA to the user profile:
CHGUSRPRF USRPRF() AUTHMTH(*TOTP)
  • Test the connection.

One instance = one TCP connection = one IBM i job.

Each instance of NTiConnection carries one TCP socket instance to connect to the IBM i. Thus there is a strong link between the instance, the connection and the IBM i job.

When an instance of NTiConnection is explicitly destroyed via .NET's Garbage Collector, the underlying TCP connection is instantly closed and destroyed in turn, causing the IBM i job to stop. This mechanism guarantees total user control of connections.

Connection string.

Like most database access providers, NTi uses a connection string to obtain IBM i connection information (user name, password, etc.). This connection string may contain sensitive information. There are a number of methods for securing the management of the connection string and configuration files.

Refer to the official .NET documentation and recommendations for their implementation.

ADO.NET implementation.

This class implements the usual methods and properties of the ADO.NET model for carrying out database access operations, in particular:

  • Open()
  • Close()
  • CreateCommand()
  • BeginTransaction()
  • Commit()
  • Rollback()

In this way, NTi integrates into any existing application developed with other vendors such as ODBC or OleDB drivers.

💡 Documentation for this default implementation can be found on any ADO.NET documentation, for example via the System.Data.Common namespace documentation .

Methods.

In addition to the functionality of the ADO.NET model, the NTiConnection class implements methods specific to the use of the IBM i, in particular for executing CL commands and calling RPG, CL... programs.

These specific methods are:

Method Description
ChangeDatabase(string database) Sets the current library for the database session.
ExecuteClCommand(string command) Executes the CL command given in the commandparameter.
CallProgram(string library, string program) Executes the program program from the library library.
CallProgram(string library, string program, List<NTiProgramParameter> parameters) Executes the library library program program with the parameters passed.

Properties.

The specific properties of the NTiConnection class allow you to define connection properties and access information about the state of the connection to the IBM i. To ensure compatibility with other providers' connection strings, some properties may correspond to several different keywords.

Property Keyword in the connection string Type Description
Server server
or system
or dsn
or host
or datasource
or data source
string IP address or domain name of the IBM i on the network.
Username user
or user id
or userid
or uid
string IBM i account username.
Password password
or pwd
string IBM i account password.
Pooling pool
or pooled
or connection pooling
or connection pool
bool Enables (true) or disables (false) connection pooling.
Enabled by default (true)..
PoolSize poolsize int Maximum number of connections kept in the pool.
DefaultDatabase schema
or default database
or database
string Default IBM i library (database only).
UseSSL ssl
or tls
or use ssl
or use tls
bool Use of an encrypted SSL/TLS connection.
Untrusted untrusted bool Force the use of SSL even if a certificate verification error occurs.
AdditionalFactor additionalfactor
or additional factor
or 2fa
or mfa
string Additional authentication factor.
AdditionalFactorCallback Func<string> Callback function to retrieve the additional authentication factor, triggered if required during connection.
SignonPort signon port short Port for the Signon service (QZDASOSIGN).
DatabasePort database port string Port for the database service (QZDASOINIT).
CommandPort command port string Port for the command and program service (QZRCSRVS).
MapperPort mapper port string Port for the port mapping service (default 449).
UseDefaultPorts use default ports bool Whether or not to use the default ports (Default ports for IBM i TCP/IP services).
UsePortsMapper use port mapper bool Whether or not to use the port mapping service. Enable this feature when the service port numbers may change over time.
LicenseLibrary license library string License library to use. By default, the KNTI library is used.
BlockingFactor blocking factor
or blockingfactor
or blocking
string Number of records to prefetch when retrieving a result.
ForceTranslate force translate int CCSID to use for forcing the translation of binary data into text (BINARY => CHAR, VARBINARY => VARCHAR, BLOB => CLOB).
NamingConvention naming convention
or naming
int SQL query naming convention. Possible values:
- 0 *SQL naming (default)
- 1 *SYS naming.
ConnectionString string Connection string used to define connection parameters before establishing the connection. The available keywords are detailed in this article.
Messages string read-only
ServerVersion string read-only Target IBM i OS version.
LobMaxSize lob threshold string Threshold size in bytes for using pointers when retrieving LOB-type fields (from 0 to 2000000).
RetreiveSuccessMessages bool Whether or not to retrieve detailed success messages in the Messages property.
DataSource string Name of the relational database of the target IBM i.
DecFloatRoundMode roundoption
or round option
NTiRoundOption (enum) Rounding mode for DECFLOAT numbers with more than 34 significant digits:
- HalfEven Round to the nearest digit, to the nearest even digit if tie
- HalfUp Round to the nearest digit, round up if tie
- Down Truncate
- Ceiling Round toward +infinity
- Floor Round toward -infinity
- HalfDown Round to the nearest digit, truncate if tie
- Up Round up
ApplicationName application name
or applicationname
string Name of the client application.
ClientAccounting client accounting
or clientaccounting
string Client accounting identifier.
ClientUserIdentifier client user identifier string End-user identifier.
ClientProgramIdentifier client program identifier string Client program identifier.
Compress compress
or use compression
bool Enables (true) or disables (false) compression of network streams to reduce bandwidth usage.
TrimCharFields trim bool Enables (true) or disables (false) automatic trimming of trailing spaces in character strings.