Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: dbi:ODBC change Port

by Anonymous Monk
on Nov 10, 2022 at 12:20 UTC ( [id://11148096]=note: print w/replies, xml ) Need Help??


in reply to dbi:ODBC change Port

This is a minimal working example

#!/usr/bin/perl -w use strict; use DBI; my $ODBCdriver = 'SQL Server'; my $SQLserver = 'RC4FA9\SQLEXPRESS'; my $SQLport = '4433'; my $SQLdatabase= 'test'; my $SQLuser = ''; my $SQLpassword= ''; my @drivers = DBI->available_drivers; print join(", ", @drivers), "\n"; my $d = join(", ", @drivers); print "DBD::ODBC "; print "not" if ($d !~ /ODBC/); print "installed\n"; print "Connecting...\n"; my $dbh = DBI->connect("dbi:ODBC:Driver={$ODBCdriver};Server=$SQLserve +r; Port=$SQLport;Database=$SQLdatabase;UID=$SQLuser;PWD=$SQLpassword" +, {PrintError => 0, RaiseError => 1, FetchHashKeyName => 'NAME_lc'}) +or die "Can't connect to the database: $DBI::errstr\n"; print "Connected...\n"; print "Disconnecting...\n"; $dbh->disconnect if ($dbh); print "Disconnected...\n";

As explained, $SQLserver does not affect the connection which always works fine. Other syntax 'Server=$SQLserver, $SQLport' does not work (but no error messages).

Replies are listed 'Best First'.
Re^2: dbi:ODBC change Port
by Corion (Patriarch) on Nov 10, 2022 at 12:50 UTC

    This does not do what you think:

    DBI->connect("dbi:ODBC:Driver={$ODBCdriver};Server=$SQLserver; Port=$S +QLport;Database=$SQLdatabase;UID=$SQLuser;PWD=$SQLpassword", {PrintError => 0, RaiseError => 1, FetchHashKeyName => 'NAME_lc'} )

    The second argument to ->connect must be undef or the database user, and the third argument must be the password. The fourth argument can optionally be the connection options, given as a hash.

    Your code "works" because you specify user and password in the DSN and that seems to override the arguments given to ->connect.

    I would recommend you change your code to the four-argument version.</>

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11148096]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-03-28 20:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found