Mono for Midrange

Information about Mono for IBM i and AIX

User Tools

Site Tools


db

Db2 for i

There are multiple ways to access Db2 from .NET:

  • With the release of IBM i 7.4, Access Client Solutions now provides support for the ODBC driver on PASE. You can use this driver with System.Data.Odbc to access Db2 natively with Mono running on IBM i. The advantage of this driver is that the code can also run on Windows and Linux; just change the connection string. You can download it from IBM without a support contract.
  • The open-source Db2 for Linux/Unix/Windows ADO.NET driver was forked to provide support when running on IBM i to access the local system; this is no longer supported now that IBM has their own workable solution. (The stock LUW driver can be used with IBM i remotely with the Db2 Connect LPP, but that incurs additional fees.)
  • The Client Access driver for ADO.NET works on Windows, but is not cross-platform.

ODBC with ACS Driver on PASE Example

Build this with mcs /r:System.Data.dll odbctest.cs. Run with mono odbctest.exe.

Note that without the latest PTFs to IBM i, you must authenticate by including a username and password in the connection string. If you're running IBM i 7.4 or the latest PTFs (SI68113 for 7.3, SI69058 for 7.2), you can omit that section of the code, and just use a connection string of DSN=*LOCAL.

// odbctest.cs
using System;
using System.Data;
using System.Data.Odbc;
 
public class Test
{
	public static void Main(string[] args)
	{
		// For compatbility with older versions of IBM i
		// without the PTF, we have to authenticate as if we
		// were on a remote system. For a remote system, you
		// need to specify a DSN pointed to your host or the
		// Client Access ODBC driver and the hostname.
		string password = "", username = "";
		Console.Write("Username: ");
		username = Console.ReadLine();
		Console.Write("Password: ");
		password = Console.ReadLine();
		// The DSN is installed by the PASE driver to refer to
		// the Client Access driver pointed locally. Append the
		// necessary authentication in the connection string.
		string connectionString =
			"DSN=*LOCAL;" +
			"UID=" + username +
			";PWD=" + password;
		IDbConnection dbcon;
		dbcon = new OdbcConnection(connectionString);
		dbcon.Open();
		Console.WriteLine (" ** Connected");
		Console.WriteLine (" ** Version {0}",
			((OdbcConnection)dbcon).ServerVersion);
		IDbCommand dbcmd = dbcon.CreateCommand();
		// This example table exists by default on IBM i.
		string sql = "SELECT LSTNAM, INIT FROM QIWS.QCUSTCDT";
		dbcmd.CommandText = sql;
		IDataReader reader = dbcmd.ExecuteReader();
		while(reader.Read()) {
			string lastName = (string) reader["LSTNAM"];
			string initials = (string) reader["INIT"];
			Console.WriteLine("Name: " +
				lastName + " " + initials);
		}
		// clean up
		reader.Close();
		reader = null;
		dbcmd.Dispose();
		dbcmd = null;
		dbcon.Close();
		dbcon = null;
	}
}

Non-Db2 databsses

This should be at the same level of support. Due to Kerberos support not being built yet, the stock Mono System.Data.SqlClient driver might not work; but you may have luck with alternative drivers.

SQLite should work as well.

Entity Framework

TODO.

db.txt · Last modified: 2019/10/17 19:34 by Calvin Buckley