PDA

View Full Version : Dsn Odbc


vietboy505
04-11-2006, 09:50 PM
How come I can't create a DSN through ODBC in Perl?
I can do it mannually and it work.


#!/usr/local/bin/perl

use Win32::ODBC;
use strict;
use warnings;

my $server="localhost,3180"; ##Server FIX, PORT
my $dsn="ODBC_WEB";
my $user = "sadmin"; #Username FIX
my $password = "rootAdmin"; #Password FIX
my $dbnameID="EmployeeInfo"; #Database FIX
my $driver="SQL Server"; #Driver FIX
my $description="Web";
my $network="DBMSSOCN";
my $databasetype="x500";

if (Win32::ODBC::ConfigDSN(
ODBC_ADD_SYS_DSN,
"$driver",
("DSN=$dsn",
"DESCRIPTION=$description",
"SERVER=$server",
"UID=$user",
"PWD=$password",
"NETWORK=$network",
))) {
print "DSN created\n";
}

my $DSN_TEST = "DSN=$dsn;UID=$user;PWD=$password;";
my $connection = new Win32::ODBC($DSN_TEST);
if (!$connection)
{
die "Could not open connection to $dsn";
}
$connection->Close();



Could not open connection to ODBC_WEB at install_ODBC.pl line 34.
It can't create a DSN.

KevinADC
04-12-2006, 12:18 AM
I don't know why but you shouldn't use the PHP tags to post perl code, it will mangle to code in certain circumstances. Use the code tags for perl.

vietboy505
04-13-2006, 11:25 PM
#!/usr/local/bin/perl

use Win32::ODBC;
use strict;
use warnings;
my $server="localhost,3180"; ##Server FIX, PORT
my $dsn="ODBC_WEB";
my $user = "sadmin"; #Username FIX
my $password = "rootAdmin"; #Password FIX
my $dbnameID="EmployeeInfo"; #Database FIX
my $driver="SQL Server"; #Driver FIX
my $description="Web";
my $network="DBMSSOCN";
my $databasetype="x500";
if (Win32::ODBC::ConfigDSN(
ODBC_ADD_SYS_DSN,
"$driver",
("DSN=$dsn",
"DESCRIPTION=$description",
"SERVER=$server",
"UID=$user",
"PWD=$password"
))) {
print "DSN created\n";
} else {
print "DSN Creation failed\n";
}

my $DSN_TEST = "DSN=$dsn;UID=$user;PWD=$password;";

if (!($db = new Win32::ODBC($DSN_TEST))){
print "Error connecting to $DSN_TEST\n";
print "Error: " . Win32::ODBC::Error() . "\n";
exit;
}

#my $connection = new Win32::ODBC($DSN_TEST) or die "$!";
#if (!$connection) {
# die "Could not open connection to $dsn";
#}
#$connection->Close();



DSN Creation failed
Error connecting to DSN=ODBC_WEB;UID=sadmin;PWD=rootAdmin;
Error: [911] [] "[Microsoft][ODBC Driver Manager] Data source name not found and
no default driver specified"