Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Answer: How do I create/remove ODBC DSN entries under Windows (Win32)?

( #432063=categorized answer: print w/ replies, xml ) Need Help??

Q&A > database programming > How do I create/remove ODBC DSN entries under Windows (Win32)? contributed by legato

Sample code, tested on platforms Windows NT through XP.
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

Comment on Answer: How do I create/remove ODBC DSN entries under Windows (Win32)?
Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2014-11-27 00:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (178 votes), past polls