Connecting to the proxy server
Now that we have configured our proxy server to
sit and wait on port 3333 on our Windows machine,
we need to tell the client Perl program on the Unix machine to use
that proxy server instead of attempting to make a direct database
connection itself.
For example, the ODBC test script above connects directly via the
DBD::ODBC module with the following
DBI->connect( ) call:
$dbh = DBI->connect( "dbi:ODBC:archaeo", "username", "password" );
This is fine for local connections, but how do we translate that into something the proxy server can use?
DBD::Proxy
makes liberal use of the optional
arguments that can be added to a DSN when specifying which database
to connect to. DBD::Proxy allows you to specify
the hostname of the machine upon which the proxy
server is running, the port number that the
proxy server is listening to, and the data source of the database that you wish the proxy server to
connect to.
Therefore, to connect to the ODBC database called
archaeo on the Windows machine
fowliswester with a proxy server running on port
3333, you should use the following
DBI-
>connect( ) syntax:
$dsn = "dbi:ODBC:archaeo"; $proxy = "hostname=fowliswester;port=3333"; $dbh = DBI->connect( "dbi:Proxy:$proxy;dsn=$dsn", '', '' );
This looks quite long-winded, but it’s a very compact and portable way to make a pass-through connection to a remote database by proxy.
Once you have connected to the proxy server and it connects to the desired data source, a valid database handle ...