http://qs321.pair.com?node_id=245553


in reply to mssqlserver dsn

Hi Michael,

Update: I forgot to mention -- this requires you to
use Win32::TieRegistry

I actually haven't tried Win32::ODBC yet; thanks for mentioning it! I'll have to look at it.

I've been creating and editing DSNs by directly manipulating the registry. While this is a bit of a hack, it works ok for my means. Here's some code for you, which works with MS SQLServer:

## create_dsn($dsn, $pointer, @servers) ## Creates a DSN named $dsn pointing to $pointer on servers named @ser +vers sub create_dsn { my $dsn = shift(@_); my $pointer = shift(@_); my @servers = @_; foreach my $server (@servers) { my $ref = $Registry->{"//$server/LMachine/Software/ODBC/ODBC.I +NI/"}; if (not exists $ref->{"$dsn/server"}) { print "$server: Creating DSN $dsn, setting to $pointer... +"; $ref->{"$dsn/"} = { 'Description' => "", 'Server' => "$pointer", 'Database' => "$dsn", 'Driver' => "C:\\WINNT\\System32\\SQLSRV32.dll", 'OEMTOANSI' => "YES", 'UseProcForPrepare' => "YES", 'TrustedConnection' => "", }; print " done\n"; print "$server: Updating ODBC Data Sources list... "; $ref->{"ODBC Data Sources/$dsn"} = "SQL Server"; print " done\n"; } else { print "$server: DSN $dsn already exists!\n"; } } print "\n\tRemember to edit the new DSNs with username and passwor +d!\n"; }
Cheers,
ibanix

P.S: I should note that this doesn't work with NT Server 4.0, just Win2k and beyond.

$ echo '$0 & $0 &' > foo; chmod a+x foo; foo;