Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: mssqlserver dsn

by ibanix (Hermit)
on Mar 24, 2003 at 21:56 UTC ( #245553=note: print w/replies, xml ) Need Help??


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;

Replies are listed 'Best First'.
Re: Re: mssqlserver dsn
by Anonymous Monk on Mar 25, 2003 at 14:45 UTC
    Hi Ibanix!!!! Thanks for the code. I'm guessing if i can't get the Win32::ODBC::ConfigDSN to work, i'll probably do something similar (edit the registry). thanks again. michael

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://245553]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2022-08-17 17:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?