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;

In reply to Re: mssqlserver dsn by ibanix
in thread mssqlserver dsn by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.