Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

[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: http://www.perlmonks.org/?node_id=37480 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( 192.168.1.1 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 a.pl Can't locate DBD/ODBC.pm 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 a.pl line 2. BEGIN failed--compilation aborted at a.pl line 2.
But, it's, see:
/System/Library/Perl/Extras/5.10.0/darwin-thread-multi-2level/DBI/Cons +t/GetInfo/ODBC.pm /System/Library/Perl/Extras/5.10.0/darwin-thread-multi-2level/DBI/W32O +DBC.pm /System/Library/Perl/Extras/5.10.0/darwin-thread-multi-2level/Win32/DB +IODBC.pm /System/Library/Perl/Extras/5.8.9/darwin-thread-multi-2level/DBI/Const +/GetInfo/ODBC.pm /System/Library/Perl/Extras/5.8.9/darwin-thread-multi-2level/DBI/W32OD +BC.pm /System/Library/Perl/Extras/5.8.9/darwin-thread-multi-2level/Win32/DBI +ODBC.pm /Users/Julio/.cpan/build/DBI-1.616-7KkONo/blib/lib/DBI/Const/GetInfo/O +DBC.pm /Users/Julio/.cpan/build/DBI-1.616-7KkONo/blib/lib/DBI/W32ODBC.pm /Users/Julio/.cpan/build/DBI-1.616-7KkONo/blib/lib/Win32/DBIODBC.pm /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/W32ODBC.pm /Users/Julio/.cpan/build/DBI-1.616-7KkONo/lib/Win32/DBIODBC.pm /opt/local/lib/perl5/site_perl/5.12.3/darwin-multi-2level/DBI/Const/Ge +tInfo/ODBC.pm /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 +C.pm
Can someone help me please? Thanks.

Comment on [URGENT] Unix perl script to connect to MS SQL Server 6.5
Select or Download Code
Re: [det-URGENT] Unix perl script to connect to MS SQL Server 6.5
by toolic (Chancellor) on Jul 07, 2011 at 15:04 UTC
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.

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://913203]
Approved by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2014-12-28 11:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (180 votes), past polls