# Solved: mysql connection using ODBC fails with error SQL_IM002



## andynic (May 25, 2007)

Mac OS X 10.6.1
perl 5.8
mysql 5.1
Installed ODBC connector: http://dev.mysql.com/downloads/connector/odbc/5.1.html#macosx-dmg

I am trying to connect to a mysql DB using the perl API.

The connect command looks like this:
$dbHandle = DBI->connect("DBI:ODBC:gfr:localhost", "gfr", "gfr");

It produces the error:
DBI connect('gfr:localhost','gfr',...) failed: [iODBC][Driver Manager]Data source name not found and no default driver specified. Driver could not be loaded (SQL-IM002) at x.pl line 30
error = [iODBC][Driver Manager]Data source name not found and no default driver specified. Driver could not be loaded (SQL-IM002)

I'v done hours of rummaging around the web to find a solution but to now avail.

In desperation I executed the following "find" command:
cd /
sudo find . -name "*odbc*" -print

It produced the following output (only relevant part shown):
./Library/ODBC/odbc.ini
./Library/ODBC/odbcinst.ini
./Users/andynic/Library/ODBC/odbc.ini
./Users/andynic/Library/ODBC/odbcinst.ini
./usr/bin/iodbc-config
./usr/bin/iodbctest
./usr/bin/iodbctestw
./usr/lib/libiodbc.2.1.18.dylib
./usr/lib/libiodbc.2.dylib
./usr/lib/libiodbc.dylib
./usr/lib/libiodbcinst.2.1.18.dylib
./usr/lib/libiodbcinst.2.dylib
./usr/lib/libiodbcinst.dylib
./usr/lib/pkgconfig/libiodbc.pc
./usr/local/bin/myodbc-installer
./usr/local/lib/libmyodbc3S-5.1.5.so
./usr/local/lib/libmyodbc3S.la
./usr/local/lib/libmyodbc3S.so
./usr/local/lib/libmyodbc5-5.1.5.so
./usr/local/lib/libmyodbc5.la
./usr/local/lib/libmyodbc5.so
./usr/local/mysql-5.1.39-osx10.5-x86_64/mysql-test/r/odbc.result
./usr/local/mysql-5.1.39-osx10.5-x86_64/mysql-test/t/odbc.test
./usr/local/mysql-5.1.39-osx10.5-x86_64/sql-bench/limits/access_odbc.cfg
./usr/local/share/mysql-connector-odbc-5
./usr/share/libiodbc
./usr/share/libiodbc/samples/iodbctest.c
./usr/share/man/man1/iodbc-config.1.gz
./usr/share/man/man1/iodbctest.1.gz
./usr/share/man/man1/iodbctestw.1

One by one I added the following "use" statments to the test script:
use DBI;
use lib "/Library/ODBC";
use lib "/usr/bin";
use lib "/usr/lib";
use lib "/usr/lib/pkgconfig";
use lib "/usr/local/bin";
use lib "/usr/local/lib";
use lib "/Users/andynic/Library/ODBC";
use lib "/usr/local/share";

All produced the error shown above.

Don't know where to turn next.
Would appreciate any ideas anyone can offer.

Thanks for your help.
Andynic
PS:
The full test script:
#!/usr/local/ActivePerl-5.8/bin/perl

use strict;
use DBI;
use lib "/Library/ODBC";
use lib "/usr/bin";
use lib "/usr/lib";
use lib "/usr/lib/pkgconfig";
use lib "/usr/local/bin";
use lib "/usr/local/lib";
use lib "/Users/andynic/Library/ODBC";
use lib "/usr/local/share";

# use DBD::ODBC;
# use DBD::mysql;

our $GCdbUn = "gfr";
our $GCdbPw = "gfr";
our $GCdbSchemaName = "gfr";

my $dbHandle = "";

print join "\n", @INC;
print "\n\n";

$dbHandle = DBI->connect("DBI:ODBC:gfr:localhost", "gfr", "gfr");
# $dbHandle = DBI->connect("DSN=mysql;UID=gfr;PWD=gfr;DATABASE=gfr");
# $dbHandle = DBI->connect("DBI:ODBC:$GCdbSchemaName", $GCdbUn, $GCdbPw);

print "error = ".DBI->errstr."\n";


----------



## andynic (May 25, 2007)

Solution:
By using a combination of the information at 
http://www.gyford.com/phil/writing/2004/06/07/installing_dbi_a.php 
and the link within that page under "these simple instructions" (http://www.truerwords.net/articles/osx/install_dbd_mysql.html)
I managed to get DBD working instead of ODBC. That is sufficient for me.
I did the above with one difference. I used a later version of the latest non-beta DBD module.
Andynic


----------

