Getting ODBC Connections Working

"Sheng Hwee, Timothy Lim" <[email protected]>
Newsgroups gmane.comp.gnome.mono.general
Message-ID <CA+ZJ0UJyGo-P1ZnE=m5jS2VD-nHsY-Mi=tejnMiTbHTb8=YbOw@mail.gmail.com>
I'm trying to get ODBC connections working on OSX (10.10.3) for a legacy
app.

======================================================
I've install MySQL/ODBC Connector (v 5.3.4 64bit) and verified the the
drivers get installed

$ myodbc-installer  -d -l

MySQL ODBC 5.3 ANSI Driver
MySQL ODBC 5.3 Unicode Driver

======================================================
I've tested both drivers using iodbc connecting via DSN or driver and they
all work

$ iodbctest

iODBC Demonstration program
This program shows an interactive SQL processor
Driver Manager: 03.52.0607.1008

Enter ODBC connect string (? shows list): ?

DSN                              | Driver
------------------------------------------------------------------------------
myodbc                           | MySQL ODBC 5.3 Unicode Driver
myodbca                          | MySQL ODBC 5.3 ANSI Driver


Enter ODBC connect string (? shows list): DSN=myodbc;UID=user;PWD=password;
Driver: 05.03.0004 (libmyodbc5w.so)

SQL>

Enter ODBC connect string (? shows list): DRIVER={MySQL ODBC 5.3 Unicode
Driver};UID=user;PWD=password;
Driver: 05.03.0004 (libmyodbc5w.so)

SQL>

Enter ODBC connect string (? shows list): DSN=myodbca;UID=user;PWD=password;
Driver: 05.03.0004 (libmyodbc5a.so)

SQL>

Enter ODBC connect string (? shows list): DRIVER={MySQL ODBC 5.3 ANSI
Driver};UID=user;PWD=password;
Driver: 05.03.0004 (libmyodbc5a.so)

SQL>

======================================================
Compiling and Running from command line gives the following error
(truncates at 'n')
"ERROR [IM002] [iODBC][Driver Manager]Data source name not found and n"

// odbc.cs

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

public class Test
{
    public static void Main(string[] args)
    {
        string[] connectionStrings = new string[]{
            "DSN=myodbc;UID=user;PWD=password;database=test;",
            "DSN=myodbca;UID=user;PWD=password;database=test;",
            "Driver={MySQL ODBC 5.3 Unicode
Driver};SERVER=localhost;uid=user;PASSWORD=password;DATABASE=test;OPTION=3",
            "Driver={MySQL ODBC 5.3 ANSI
Driver};SERVER=localhost;uid=user;PASSWORD=password;DATABASE=test;OPTION=3"
        };
        IDbConnection dbcon;

        foreach(var connectionString in connectionStrings){
            try
                Console.WriteLine(connectionString);
                dbcon = new OdbcConnection(connectionString);
                dbcon.Open();
                Console.WriteLine("    CONNECTED");
                dbcon.Close();
            }
            catch (System.Exception e) {
                Console.WriteLine("    Error: " + e.Message);
            }
        }
    }
}

/*
Compile
    mcs odbc.cs -r:System.Data

Run
    mono odbc.exe

Sample Output (notice the truncated text)
    DSN=myodbc;UID=user;PWD=password;database=test;
        Error: ERROR [IM002] [iODBC][Driver Manager]Data source name not
found and n
    DSN=myodbca;UID=user;PWD=password;database=test;
        Error: ERROR [IM002] [iODBC][Driver Manager]Data source name not
found and n
    Driver={MySQL ODBC 5.3 Unicode
Driver};SERVER=localhost;uid=user;PASSWORD=password;DATABASE=test;OPTION=3
        Error: ERROR [IM002] [iODBC][Driver Manager]Data source name not
found and n
    Driver={MySQL ODBC 5.3 ANSI
Driver};SERVER=localhost;uid=user;PASSWORD=password;DATABASE=test;OPTION=3
        Error: ERROR [IM002] [iODBC][Driver Manager]Data source name not
found and n
*/

======================================================
Running from Xamarin Studio on OSX gives a heap error

DSN=myodbc;UID=user;PWD=password;database=test;
    Error: Garbage collector could not allocate 16384 bytes of memory for
major heap section.


======================================================
Configuration files for
$ myodbc-installer
$ iodbctest
are ~/Library/ODBC/odbc.ini
~/Library/ODBC/odbcinst.ini


$ cat ~/Library/ODBC/odbc.ini
[ODBC Drivers]
MySQL ODBC 5.3 Unicode Driver = Installed
MySQL ODBC 5.3 ANSI Driver    = Installed

[MySQL ODBC 5.3 Unicode Driver]
Driver = /usr/local/lib/libmyodbc5w.so

[MySQL ODBC 5.3 ANSI Driver]
Driver = /usr/local/lib/libmyodbc5a.so


$ cat ~/Library/ODBC/odbcinst.ini
[ODBC Drivers]
MySQL ODBC 5.3 Unicode Driver = Installed
MySQL ODBC 5.3 ANSI Driver    = Installed

[MySQL ODBC 5.3 Unicode Driver]
Driver = /usr/local/lib/libmyodbc5w.so

[MySQL ODBC 5.3 ANSI Driver]
Driver = /usr/local/lib/libmyodbc5a.so

======================================================
Adding tracing to the odbc.ini file gives the log when I run the app in
Xamarin studio.

https://forums.xamarin.com/discussion/comment/116545/#Comment_116545

It goes on for a long time before and I have to force close the app and it
gets stuck trying to connect using the first connection string

======================================================
Any advice on how to debug things would be highly appreciated

_______________________________________________
Mono-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-list
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.