I am trying to use Mono to access an Informix (IDS 11.7) database on Linux (Centos 5.4)
I can access a mysql database using the small program below with no problems. I can "isql unicare" with no problem, so it seems the unixODBC is OK.
These are my odbc.ini and odbcinst.ini files (using suggestions supplied by Adam Williams
to Nick Gorham found at http://www.unixodbc.org/doc/informix.html )
/etc/odbc.ini
[MyDSN]
DRIVER=/usr/lib/libmyodbc3.so
SERVER=localhost
DATABASE=unicare
UID=root
PWD=MyWord
PORT=
[unicare]
Driver=Informix
Server=unicare
Database=unicare
CLIENT_LOCALE=en_us.8859-1
DB_LOCALE=en_us.8859-1
TRANSLATIONDLL=/u/Informix11_7/lib/esql/igo4a304.so
/etc/odbcinst.ini
##-Example driver definitinions
##-Included in the unixODBC package
[PostgreSQL]
Description = ODBC for PostgreSQL
Driver = /usr/lib/libodbcpsql.so
Setup = /usr/lib/libodbcpsqlS.so
FileUsage = 1
# Driver from the MyODBC package
# Setup from the unixODBC package
[MySQL]
Description = ODBC for MySQL
Driver = /usr/lib/libmyodbc.so
Setup = /usr/lib/libodbcmyS.so
FileUsage = 1
[Informix]
Description=Informix IDS 11.7
Driver=/u/Informix11_7/lib/cli/libifcli.so
##Driver=/u/Informix11_7/lib/cli/iclit09b.so
APILevel=1
ConnectFunctions=YYY
DriverODBCVer=03.51
FileUsage=0
SQLLevel=1
smProcessPerConnect=Y
Here is the sample program found on http://mono-project.com/ODBC, where I have used the original successfully on a MySQL database, and then changed to this to match the DSN of the Informix database.
Again, "isql unicare" works and reads the employee table of the Informix database. Apologies if the script looks nasty, but I am battling with the editor here!
TestExample.cs
using System;
using System.Data;
using System.Data.Odbc;
public class Test
{
public static void Main(string[] args)
{
// have an ODBC DSN setup named MYSQLDSN
// that accesses a MySQL database via
// MyODBC driver for ODBC with a
// hostname of localhost and database test
string connectionString =
"DSN=unicare;" +
"UID=bob;" +
"PWD=BobWord";
IDbConnection dbcon;
dbcon = new OdbcConnection(connectionString);
dbcon.Open();
IDbCommand dbcmd = dbcon.CreateCommand();
// requires a table to be created named employee
// with columns firstname and lastname
// such as,
// CREATE TABLE employee (
// firstname varchar(32),
// lastname varchar(32));
string sql =
"SELECT firstname, lastname " +
"FROM employee";
dbcmd.CommandText = sql;
IDataReader reader = dbcmd.ExecuteReader();
while(reader.Read()) {
string FirstName = (string) reader["firstname"];
string LastName = (string) reader["lastname"];
Console.WriteLine("Name: " +
FirstName + " " + LastName);
}
// clean up
reader.Close();
reader = null;
dbcmd.Dispose();
dbcmd = null;
dbcon.Close();
dbcon = null;
}
}
But when I run it, I get ...
$ mono TestExample.exe
Unhandled Exception: System.Data.Odbc.OdbcException: ERROR [I
Should I use the odbc.ini and odbcinst.ini (edited) from Informix?
If I use a more regular looking odbc*ini set then I get a more verbose errror message Unhandled Exception: System.Data.Odbc.OdbcException: ERROR [IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified at System.Data.Odbc.OdbcConnection.Open () [0x00000] in
<filename unknown>
:0
and I am suspicious that this garbled message that I am getting is this; as reported on http://article.gmane.org/gmane.comp.gnome.mono.general/35093
Any ideas or help would be greatly appreciated.