[Mono-dev] Debug mono ODBC ?

quandary quandary82 at hailmail.net
Sat Aug 6 05:00:20 EDT 2011

Hi, question:

In short, I want to know how I can debug ODBC with mono.
A) My code just freezes at (string) reader["BEZEICHNUNG"];
B) mono --debug myfile.exe shows no messages

Since the available memory goes down for as long as the program runs, my
guess is that
(string) reader["BEZEICHNUNG"];
never gets a '\0' character.

Below some background info:

I'm trying to connect to an Access DB on Linux (Ubuntu 11.04, mono 2.10.2).

The way I do this:
1. Install mdbtools-dev
2. Install unixodbc-dev
3. Create an ODBC DSN entry in /etc/odbc.ini

Description = Microsoft Access Database
Database = /root/DBs/myAccessDB.mdb
Driver = /usr/lib/libmdbodbc.so
Setup =
FileUsage = 1
CPTimeout =
CPReuse =

4. Test the ODBC connection with OpenOffice base --> nothing (no error
either) with Access DB
    ODBC works for Firebird + MySQL, so no setup bug, probably
OpenOffice bug
5. Figure out whether it's a mdbtools-bug, with mdbtools-viewer (gmdb2) 
--> success, can see db + content, so no mdbtools-bug, so it's either an
ODBC or an OpenOffice bug
6. Test whether it is an ODBC or an OpenOffice bug: ODBC query with isql
--> success, I can retrieve the Access data via the ODBC connection, so
no ODBC bug, it follows it's an OpenOffice bug
7. Write a mono ODBC test program.
8. Test --> crashes on Access (same query as with isql)
9. Test whether the program is wrong: Use same program on MySQL ODBC
---> Works fine
10. It follows --> We have a mono bug here.

Here my code:

using System;
using System.Data;
using System.Data.Odbc;

namespace OdbcTest
    class MainClass
        // https://help.ubuntu.com/community/ODBC
        // http://ngommans.ca/howto/jdbc-odbc/
        // http://www.firebirdnews.org/?p=1324
        // http://manpages.ubuntu.com/manpages/hardy/man1/isql-fb.1.html
        // http://www.mono-project.com/ODBC
        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=MyDSN;" +
            "UID=;" +
       //IDbConnection dbcon;
            OdbcConnection dbcon;
       dbcon = new OdbcConnection(connectionString);
       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 * from ART";
       dbcmd.CommandText = sql;
        IDataReader reader = dbcmd.ExecuteReader();
       while(reader.Read()) {
            // Stays here forever
            string FirstName = (string) reader["BEZEICHNUNG"];
            string LastName = (string) reader["MEINHEIT"];
            Console.WriteLine("modul form: " + FirstName + " " + LastName);
       // clean up
       reader = null;
                DataTable dt = new DataTable();
    OdbcDataAdapter da = new OdbcDataAdapter(sql,dbcon);
            da.Fill(dt); // Takes forever
       dbcmd = null;
       dbcon = null;

More information about the Mono-devel-list mailing list