use Win32::ODBC; print "Add DSN successful" if add_dsn('TestDSN'); print "Del DSN successful" if del_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 sub del_dsn { my $dsn = shift; my $result = Win32::ODBC::ConfigDSN( ODBC_REMOVE_DSN, "SQL Server", ("DSN=$dsn") ); ## see add_dsn comments for more detail. unless ($result) { print STDERR "I failed to remove $dsn : " .Win32::ODBC::Error()."\n"; return undef; } return 1; } #^^ del_dsn