[Mono-dev] Debug mono ODBC ?

quandary quandary82 at hailmail.net
Sat Aug 6 06:43:34 EDT 2011


I've now ripped the entire System.Data.Odbc out of the mcs class library
and into my project.

Stepping into, and pausing where it is forever,  I get

                        ret = libodbc.SQLGetData (hstmt, ColIndex,
col.SqlCType, buffer, bufsize, ref outsize);
                        if (ret == OdbcReturn.Error)
                            break;

in OdbcDataReader.cs

where SQLGetData is

        [DllImport ("odbc32.dll", CharSet = CharSet.Unicode)]
        internal static extern OdbcReturn SQLGetData (
            IntPtr StatementHandle,
            ushort ColumnNumber,
            SQL_C_TYPE TargetType,
            byte[] TargetPtr,
            int BufferLen,
            ref int Len);

with
hstmt = 0x9489d00
ColIndex = 3
col.SqlCType = char
buffer = byte[255]
bufsize= 255
and ref outsize = 12

from msdn

SQLRETURN SQLGetData(
      SQLHSTMT       StatementHandle,
      SQLUSMALLINT   Col_or_Param_Num,
      SQLSMALLINT    TargetType,
      SQLPOINTER     TargetValuePtr,
      SQLLEN         BufferLength,
      SQLLEN *       StrLen_or_IndPtr);




I assume I now have to write a C test program and see what goes wrong.

I suppose "odbc32.dll" maps to
unixodbc-dev: /usr/lib/libodbc.so
 
Is that right ?
Or where can I see what odbc32.dll maps to ?

By the way, if I want to resume after pause, I get (MonoDevelop 2.4):

Unhandled Exception. MonoDevelop will now close.

Details:
System.ArgumentNullException: Argument cannot be null.
Parameter name: thread
  at Mono.Debugger.Soft.StepEventRequest..ctor
(Mono.Debugger.Soft.VirtualMachine vm, Mono.Debugger.Soft.ThreadMirror
thread) [0x00000] in <filename unknown>:0
  at Mono.Debugger.Soft.VirtualMachine.CreateStepRequest
(Mono.Debugger.Soft.ThreadMirror thread) [0x00000] in <filename unknown>:0
  at Mono.Debugging.Soft.SoftDebuggerSession.<OnNextLine>m__9
(System.Object ) [0x00000] in <filename unknown>:0


On 08/06/2011 11:00 AM, quandary wrote:
> Hi, question:
>
> In short, I want to know how I can debug ODBC with mono.
> Because
> A) My code just freezes at (string) reader["BEZEICHNUNG"];
> and
> 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
>
> [MyDSN]
> 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://user.services.openoffice.org/en/forum/viewtopic.php?f=40&t=1416
>         // 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=;" +
>           "PWD=";
>        //IDbConnection dbcon;
>             OdbcConnection 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 * 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.Close();
>        reader = null;
>      
>     /*
>                 DataTable dt = new DataTable();
>     OdbcDataAdapter da = new OdbcDataAdapter(sql,dbcon);
>             da.Fill(dt); // Takes forever
>             Console.WriteLine(dt.Rows.Count.ToString());
>              */
>            
>        dbcmd.Dispose();
>        dbcmd = null;
>        dbcon.Close();
>        dbcon = null;
>         }
>     }
> }
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list



More information about the Mono-devel-list mailing list