Operating System - HP-UX
1831043 Members
2427 Online
110019 Solutions
New Discussion

Re: Accessing Sql Server thur Perl on HP-UX

 
Sivakumar Murugan
Occasional Contributor

Accessing Sql Server thur Perl on HP-UX

I want to connect Sql server database from my perl script. I have installed DBD::ODBC module and unixODBC pacakge in the unix server
please find the versions below:
perl 5.8.3
DBD-ODBC 1.15
DBI 1.52
when i run the below perl script am getting the following error
[unixODBC][Driver Manager]Data source name not found, and no default
driver specified (SQL-IM002)

This is my script:

#!/opt/perl5/bin/perl
use strict;
use DBI;

my $DSN = "DRIVER={SQL Server};Server=d3w9201G;database=Test;uid=user;pwd=pwd";

my $dbh = DBI->connect("dbi:ODBC:$DSN") or die "$DBI::errstr\n";

my $getsdate =
$dbh->prepare("SELECT getdate()");
$getsdate->execute;
my $sdate = $getsdate->fetchrow_array;
print "$sdate\n";

Can anybody help on this to reslove this issue?

Thanks in Advance.

Shiv.
1 REPLY 1
Ralph Grothe
Honored Contributor

Re: Accessing Sql Server thur Perl on HP-UX

Hi Shiv,

Though I am afraid that I have never had any exposure to MSSQL DB servers,
I think that your DSN may be malformed.
I would suggest that you carefully read the POD of DBD::ODBC and some API reference of your DBMS (I would think that even those for other programming languages like C(++), Java etc. would suffice).
There must somewhere appear examples how a proper DSN string needs to be formatted.
Also, for now forget about any other SQL code
until you successfully have connected to your DB.
Usually invocation of DBI's generic constructor along with a ping should be enough for testing this.
e.g.

DBI->connect($DSN, {PrintError=>1})->ping


Of course, it goes without saying that the user who is running the connect requires to have been granted at least connect (and probably some select) permissions for the targeted DB (and views).

Good Luck

Ralph
Madness, thy name is system administration