bfdi533 has asked for the wisdom of the Perl Monks concerning the following question:

I have some perl code that I am trying to get working. It runs on win32 (Windows 2003 Server) on ActiveState Perl (Build 631). The mysql server is running on a Linux machine that I have no problems connecting to otherwise. The code is (IP and username sanitized for security):
#!perl.exe use strict; use warnings; use Win32::OLE; use Win32::OLE::Variant; use Win32::OLE::Const 'Microsoft Outlook'; use DBI(); my $dbhost = '1.2.3.4'; my $dbuser = 'user'; my $dbdb = 'ssis'; my $dsn = "DBI:mysql:database=$dbdb;host=$dbhost"; my $dbh; print "Connecting to DB ...\n"; print "dsn: $dsn\n"; $dbh = DBI->connect($dsn,$dbuser,'') or die "couldn't connect to $dbho +st: " . DBI->errstr . "\n"; print "Done with DB connection\n";
And the output is:
C:\Data\Scripts\Exchange>mysql_connect.pl Connecting to DB ... dsn: DBI:mysql:database=ssis;host=1.2.3.4 C:\Data\Scripts\Exchange>

update: Just tried this for kicks with a different and unauthorized username and it behaves in exactly the same way as it does with a correct and authorized username?!

Any thoughts as to why this just dies without the error message and without printing the text after the connect code?

Ed

Replies are listed 'Best First'.
Re: connecting to Mysql from Win32
by mbeast (Beadle) on Oct 22, 2004 at 17:45 UTC
    how about instead of my $dsn = "DBI:mysql:database=$dbdb;host=$dbhost"; you do

    my $dsn = "DBI:mysql:$dbdb:$dbhost";
      Interesting thought. But that does not work either nor does it throw an error message ...

      Ed

Re: connecting to Mysql from Win32
by bfdi533 (Friar) on Oct 22, 2004 at 18:20 UTC
    Well, so I thought I might check into this further so I ran this code with "perl -d" and the last part of that output is as follows:
    DB<1> dsn: DBI:mysql:database=ssis;host=128.83.153.43 main::(mysql_connect.pl:21): $dbh = DBI->connect($dsn,$dbuser,$dbpa +ss) or die "couldn't connect to $dbhost: " . DBI->errstr . "\n"; DB<1> x $dbh 0 undef DB<2> n Signal SEGV at C:/Perl/site/lib/DBI.pm line 486 DBI::connect('DBI', 'DBI:mysql:database=ssis;host=1.2.3.4', 'u +ser', 'pass') called at mysql_connect.pl line 21
    Any thoughts on the SEGV?

      Any thoughts on the SEGV?

      Well I assume you know a SEGV is a SEGmentation Violation aka a SEGFAULT. Given that I and many others connect to Linux based Mysql databases from Win32 using DBI without any issues the question is why?

      The DB connection is a TCP one to 3306 so your Win32 and Linux firewalls need to allow that. You don't show it but I assume that your real connection string includes server *and* port:

      'dbname=DATABASENAME;host=MYSQLSERVER.DOMAIN.COM:3306'

      You should be able to connect via telnet :

      C:\> telnet mysqlserver.domain.com 3306 0 4.0.20-standardZZ5;eo{=,&#9787; Connection to host lost. C:\>
      And see a response like the one above from your remote Mysql server. If not you have a firewall issue to fix.

      Assuming you are pointing the connect string at the server:port where your Mysql server lives then a likely reason is that you are using binaries for DBI and DBD::Mysql that are linked against the wrong C libraries for your system. The first suggestion is to install the latest versions of DBI and DBD::Mysql you can find. Also just make a trivial test script that connects, makes a query and disconnects to make sure it is not an issue with DBI and the other modules you are using. If you have CL.EXE you could compile DBI and DBD::Mysql yourself which would almost certainly resolve the issue.

      cheers

      tachyon

Re: connecting to Mysql from Win32
by jdtoronto (Prior) on Oct 22, 2004 at 17:40 UTC
    Scratches head.....

    I don't see a database driver there use DBD::mysql; for example.

    jdtoronto

      No need. DBI loads it for you.
        Your code works for me. I know this is the obvious but DBD::mysql is installed right? As well your password is empty, do you really have an empty password?

        Update:
        MySQL 4.1.1
        Activestate Perl, v5.8.4
        Win 2000
        DBD-mysql 2.9003

Re: connecting to Mysql from Win32
by PodMaster (Abbot) on Oct 23, 2004 at 09:05 UTC
    Have you tried turning TRACING on (as per DBI documentaion)?

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.