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.

In reply to [URGENT] Unix perl script to connect to MS SQL Server 6.5 by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.