use DBI;
$dbh = DBI->connect('dbi:ODBC:DSN', 'user', 'password');
| [reply] [d/l] |
I read the question to be asking for a way to actually create a DSN for an ODBC driver. I don't think that can be done via DBI at all. On the other hand, the syntax you gave is correct for accessing an ODBC source via DBI, which might be what was wanted. I'm not really clear what the OP is asking.
-Tats
| [reply] |
| [reply] |
use Win32::ODBC;
print "Add DSN successful" if add_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
This code tested on Win NT,95,98,2k,2k3,XP with ActiveState Perl 5.8.6
Anima Legato .oO all things connect through the motion of the mind
| [reply] [d/l] |