Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
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 avoiding work at the Monastery: (7)
As of 2015-07-02 00:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (25 votes), past polls