Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • DBD::ODBC (Score:3, Informative)

    We use DBD::ODBC and have been very happy. We connect like this (took me a while to work out so hope this helps...)

    my $dsn = join "", (
    "dbi:ODBC:",
    "Driver={SQL Server};",
    "Server=gort;",
    "UID=gpd;",
    "PWD=gpd;",
    "Database=gort_db",
    );

    my $user = 'gpd';
    my $passwd = 'gpd';

    my $db_options = {
    PrintError => 1,
    RaiseError => 1,
    AutoCommit => 0, #Use transactions
    };

    my $dbh =
    DBI->connect($dsn, $user, $passwd, $db_options)

    • You realize, of course, that with RaiseError set, your code will never hit that call to exit_msg(), die'ing before it gets there if there are any problems with the connect.
      • You realize, of course, that with RaiseError set, your code will never hit that call to exit_msg()

        That certainly hasn't been my experience - perhaps things have changed with recent versions of DBI. I understood that RaiseError was a property of the database handle object which wouldn't exist until the connect method had returned successfully. Errors during the connect itself are handled by returning undef and storing the error message in $DBI::errstr.

        • I think you have misunderstood. My understanding is that if you have RaiseError set in the options you pass to the connect method, connect will die if unsuccessful. I just ran a short experiment to check, and it is true for Oracle, at least when you attempt to log in to an instance with an incorrect password. YMMV with other drivers or other specific errors, I suppose.

          I now connect always with RaiseError => 1, PrintError => 0 (to avoid duplicates; DBI docs say to do this, btw), and AutoCommit => 0.

          --
          J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers