Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

How do I connect to Microsoft SQL server 6.5?

( #37480=categorized question: print w/ replies, xml ) Need Help??
Contributed by Anonymous Monk on Oct 19, 2000 at 13:04 UTC
Q&A  > database programming


Description:

What modules do I need and where can I get them from,

Hoping for enlightenment
Sparkie

Answer: How do I connect to Microsoft SQL server 6.5?
contributed by patgas

It took me weeks to figure out the actual code on how to connect to SQL Server without setting up a DSN on the machine. Hopefully I can spare someone the same pain.

This should give you the basics:

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;
Answer: How do I connect to Microsoft SQL server 6.5?
contributed by wardk

I would second using

  • DBI
  • DBD::ODBC

Be sure to install MDAC 2.1 (or higher)

Also, ignore any advice to use DSN's on the machine, you should really build a complete connect string in your code. that way you stay portable. Nothing like moving it to a newer bigger machine (inevitable with NT) and then having to hand-build a DSN.

You should get suprisingly good results from a combination of Perl and ODBC. It sure beats using that other product from our pals in Redmond.

Answer: How do I connect to Microsoft SQL server 6.5?
contributed by agoth

Modules:

  • DBI
  • DBD::ODBC

You can get them from:
CPAN

Answer: How do I connect to Microsoft SQL server 6.5?
contributed by infoninja

Also, you might want to try FreeTDS and DBD::Sybase. MS-SQL Server is based off Sybase and uses TDS. I've had good results using the modules/drivers mentioned above.

Answer: How do I connect to Microsoft SQL server 6.5?
contributed by Caillte

The DBI module is not fun for the uninitiated... have a read here for some good tutorials.

Please (register and) log in if you wish to add an answer



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • 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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (8)
    As of 2015-07-08 03:53 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (94 votes), past polls