Hi Gurus,
I need to connect to MSSQL SERVER (express edition on remote system) through
a perl script. But I get the following error with the code below can any
body help me in that.
############ ERROR
Use of uninitialized value $Win32::ODBC::ErrConn in concatenation (.) or
string
at C:/Perl/lib/Win32/ODBC.pm line 785.
Unable to connect to DSN Databasesysadm:[17] [] "[Microsoft][ODBC SQL Server
Dri
ver][TCP/IP Sockets]SQL Server does not exist or access denied."
############ ERROR
################## CODE SNIP
my $user="sqlserver";
my $pw="servertest";
my $dsn="Databasesysadm"; # name of the DSN we will be using
my $SERVER="remotemachine";
my $DB="projDB";
my %dsnavail;
my @cols;
my @dbs;
my $table;
my @tables;
die "Unable to query available DSN's".Win32::ODBC::Error( )."\n" unless
(%dsnavail = Win32::ODBC::DataSources( ));
foreach my $key (keys %dsnavail)
{
print "$key=$dsnavail{$key}\n";
}
if (!defined $dsnavail{$dsn})
{
die "unable to create DSN:".Win32::ODBC::Error( )."\n"
unless (Win32::ODBC::ConfigDSN(ODBC_ADD_DSN, "SQL Server",
("DSN=$dsn", "DESCRIPTION=DSN for PerlSysAdm", "SERVER=remotemachine",
"DATABASE=$DB", "NETWORK=DBMSSOCN",)));
}
my $dbh = new Win32::ODBC("DSN=$dsn;UID=$user;PWD=$pw;");
die "Unable to connect to DSN $dsn:".Win32::ODBC::Error( )."\n" unless
(defined $dbh);
# find the databases on the server
if (defined $dbh->Sql(q{SELECT name from sysdatabases}))
{
die "Unable to query databases:".Win32::ODBC::Error( )."\n";
}
$dbh->Close( );
die "Unable to delete DSN:".Win32::ODBC::Error( )."\n" unless
(Win32::ODBC::ConfigDSN(ODBC_REMOVE_DSN, "SQL Server","DSN=$dsn"));
################## CODE SNIP
Thanks,
Siva