Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

[URGENT] Unix perl script to connect to MS SQL Server 6.5

by Anonymous Monk
on Jul 07, 2011 at 14:55 UTC ( #913203=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I need to connect to a Microsoft SQL Server 6.5 from my perl code, I noted that this require some special steps. I found a good reference at: And it has a nice example:
use DBI; use DBD::ODBC; my ( $data_source, $database, $user_id, $password ) = qw( server datab +ase user password ); my $conn_string = "driver={SQL Server};Server=$data_source;Database=$d +atabase;UID=$user_id;PWD=$password"; my $dbh = DBI->connect( "DBI:ODBC:$conn_string" ) or die $DBI::errstr; my $sql = "SELECT * FROM tbl_Foo (NOLOCK)"; my $sth = $dbh->prepare( $sql ); $sth->execute; while ( my $result = $sth->fetchrow_hashref ) { # Your fields can be accessed through the $result hashref, for exa +mple: print $result->{First_Name}; } $dbh->disconnect;
And I modified it, I don't know what is the database name, so I guess that "master" should be fine, and also I don't have a sa password, it's blank. I replaced it such as: my ( $data_source, $database, $user_id, $password ) = qw( master sa ); Is this correct? If not, can you please tell me correct way? Also, when I try execute I get the error that the module is not present:
$ perl Can't locate DBD/ in @INC (@INC contains: /opt/local/lib/perl5/ +site_perl/5.12.3/darwin-multi-2level /opt/local/lib/perl5/site_perl/5 +.12.3 /opt/local/lib/perl5/vendor_perl/5.12.3/darwin-multi-2level /op +t/local/lib/perl5/vendor_perl/5.12.3 /opt/local/lib/perl5/5.12.3/darw +in-multi-2level /opt/local/lib/perl5/5.12.3 /opt/local/lib/perl5/site +_perl /opt/local/lib/perl5/vendor_perl .) at line 2. BEGIN failed--compilation aborted at line 2.
But, it's, see:
/System/Library/Perl/Extras/5.10.0/darwin-thread-multi-2level/DBI/Cons +t/GetInfo/ /System/Library/Perl/Extras/5.10.0/darwin-thread-multi-2level/DBI/W32O /System/Library/Perl/Extras/5.10.0/darwin-thread-multi-2level/Win32/DB /System/Library/Perl/Extras/5.8.9/darwin-thread-multi-2level/DBI/Const +/GetInfo/ /System/Library/Perl/Extras/5.8.9/darwin-thread-multi-2level/DBI/W32OD /System/Library/Perl/Extras/5.8.9/darwin-thread-multi-2level/Win32/DBI /Users/Julio/.cpan/build/DBI-1.616-7KkONo/blib/lib/DBI/Const/GetInfo/O /Users/Julio/.cpan/build/DBI-1.616-7KkONo/blib/lib/DBI/ /Users/Julio/.cpan/build/DBI-1.616-7KkONo/blib/lib/Win32/ /Users/Julio/.cpan/build/DBI-1.616-7KkONo/lib/DBI/Const/GetInfo/ODBC.p +m /Users/Julio/.cpan/build/DBI-1.616-7KkONo/lib/DBI/ /Users/Julio/.cpan/build/DBI-1.616-7KkONo/lib/Win32/ /opt/local/lib/perl5/site_perl/5.12.3/darwin-multi-2level/DBI/Const/Ge +tInfo/ /opt/local/lib/perl5/site_perl/5.12.3/darwin-multi-2level/DBI/W32ODBC. +pm /opt/local/lib/perl5/site_perl/5.12.3/darwin-multi-2level/Win32/DBIODB
Can someone help me please? Thanks.

Replies are listed 'Best First'.
Re: [det-URGENT] Unix perl script to connect to MS SQL Server 6.5
by toolic (Bishop) on Jul 07, 2011 at 15:04 UTC
Re: [URGENT] Unix perl script to connect to MS SQL Server 6.5
by mje (Curate) on Jul 08, 2011 at 08:13 UTC

    You appear to have WIN32::ODBC installed but not DBD::ODBC. They are not the same. BTW, I doubt you need to use DBD::ODBC. Also, whether you can define Driver as "SQL Server" will depend on whether you have actually installed an ODBC driver called "SQL Server" - if you haven't installing DBD::ODBC is not going to make a difference i.e., you need to install an ODBC driver for SQL Server in addition to DBD::ODBC.

Re: [URGENT] Unix perl script to connect to MS SQL Server 6.5
by tokpela (Chaplain) on Jul 07, 2011 at 15:28 UTC

    I did this a long time ago in another job using the dbiproxy script that is included in DBI.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://913203]
Approved by toolic
and the fire pops...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2018-06-22 11:43 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (124 votes). Check out past polls.