use Win32::ODBC;
print "Add DSN successful" if add_dsn('TestDSN');
sub add_dsn {
my $dsn = shift;
my $result = Win32::ODBC::ConfigDSN(
ODBC_ADD_DSN, "SQL Server", ## this last is the driver name
( ##options
"DSN=$dsn", ## DSN identifier
"NETWORK=DBMSSOCN", ## use TCP/IP library
"SERVER=test_server", ## server name
"DATABASE=test_db", ## database name
"DESCRIPTION=My test DSN"
)
); ## end of ConfigDSN call
unless ($result) {
print STDERR "Couldn't create $dsn because of error: "
.Win32::ODBC::Error()."\n";
return undef;
}
return 1;
} #^^ add_dsn
This code tested on Win NT,95,98,2k,2k3,XP with ActiveState Perl 5.8.6
Anima Legato
.oO all things connect through the motion of the mind