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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-24 23:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found