beautypg.com

IBM Data Server DB2 User Manual

Page 280

background image

266

DB2 Deployment Guide

# Creating dsn from command line arguments.
$dsn = "HOSTNAME=" . $ARGV[0] .
";PORT=" . $ARGV[1] .
";DATABASE=" . $ARGV[2] .
";PROTOCOL=TCPIP" .
";UID=" . $ARGV[3] .
";PWD=" . $ARGV[4];

print "Trying to establish connection...\n";
$dbh = DBI->connect("dbi:DB2:$dsn",
"", "",
{PrintError => 0}
) || die "Database connection not made: $DBI::errstr";
print "Connection successful.\n";
print "Closing connection...\n";
$dbh->disconnect();
print "Connection closed.\n";