* IBM DB2 Data Provider
- ADO.NET Data Provider for IBM DB2 Universal Database
- Exists in namespace DB2ClientCS and assembly Mono.Data.DB2Client
- The source code exists at mcs/class/Mono.Data.DB2Client
- Requires the Call Level Interface to IBM DB2 shared library. This
is db2cli.dll on Windows. The IBM DB2 CLI API is very similar to the ODBC API. If
you take a look at Mono's System.Data.Odbc ODBC provider, you will see the
DllImport's have similiar function names.
- IBM DB2 Provider created by Christopher Bockner.
- Bugs with Mono or the data provider should be reported
in Mono's Bugzilla here. If you
do not have Bugzilla user account, it is free
and easy to
create one here.
** Current Status
- Compiles on Windows and Linux. Works on Windows. Still needs to be tested on Linux.
- Able to connect to IBM DB2
- Able to execute DML, such as, CREATE TABLE via ExecuteNonQuery()
- Christopher says it can retrieve data via the DB2ClientDataReader
** Action Plan
- Still needs work to get it to retrieve data via ExecuteReader() and
use the data reader to read data.
** Testing
In order to test.
- Have working mono and mcs setup
- Have access to an IBM DB2 database. If you do not have access, download the
IBM DB2 software. There
are versions for Windows, Linux, AIX, and Sun Solaris.
- Make sure the assembly Mono.Data.DB2Client.dll was built and installed
where the other class libraries are installed.
- If you do not have the source to mcs, get the source from
here
- Has a ConnectionString format like ODBC
- Here is a ConnectionString format if you have a DSN setup:
"DSN=dataSetName;UID=myuserid;PWD=mypassword"
- Here is a ConnectionString format if you do not have a DSN (have not
gotten this to work though, so, I am open to suggestions):
"DRIVER={DB2 Driver};SERVER=localhost;DATABASE=test;UID=myuserid;PASSWORD=mypassword"
- In mcs/class/Mono.Data.DB2Client/Test/DBConnTest, you will find
a DBConnTest.cs.
- To build DBConnTest:
mcs DBConnTest.cs -r System.Data.dll -r Mono.Data.DB2Client.dll
- On Windows via Cygwin:
mono C:/cygwin/home/MyHome/mono/install/bin/mcs.exe DBConnTest.cs \
-lib:C:/cygwin/home/MyHome/mono/install/lib \
-r System.Data.dll -r Mono.Data.DB2Client.dll
- To run it on mono:
mono DBConnTest.exe database userid password
C# Example:
using System;
using System.Data;
using Mono.Data.DB2Client;
public class Test
{
public static void Main(string[] args)
{
string connectionString =
"DSN=sample;UID=db2admin;PWD=mypass";
IDbConnection dbcon = new DB2ClientConnection(connectionString);
dbcon.Open();
IDbCommand dbcmd = dbcon.CreateCommand();
string sql =
"CREATE TABLE mono_db2_test1 ( " +
" testid varchar(2), " +
" testdesc varchar(16) " +
")";
dbcmd.CommandText = sql;
dbcmd.ExecuteNonQuery();
dbcmd.Dispose();
dbcmd = null;
dbcon.Close();
dbcon = null;
}
}
Building C# Example:
- Save the example to a file, such as, TestExample.cs
- Build on Linux:
mcs TestExample.cs -r System.Data.dll \
-r Mono.Data.DB2Client.dll
- Build on Windows via Cygwin:
mono C:/cygwin/home/MyHome/mono/install/bin/mcs.exe \
TestExample.cs \
-lib:C:/cygwin/home/MyHome/mono/install/lib \
-r System.Data.dll -r Mono.Data.DB2Client.dll
Running the Example:
mono TestExample.exe