http://www.perlmonks.org?node_id=37480

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question: (database programming)

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

Hoping for enlightenment
Sparkie

Originally posted as a Categorized Question.

  • Comment on How do I connect to Microsoft SQL server 6.5?

Replies are listed 'Best First'.
Re: How do I connect to Microsoft SQL server 6.5?
by patgas (Friar) on Jan 23, 2002 at 20:43 UTC

    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;
Re: How do I connect to Microsoft SQL server 6.5?
by wardk (Deacon) on Oct 19, 2000 at 22:37 UTC

    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.

Re: How do I connect to Microsoft SQL server 6.5?
by agoth (Chaplain) on Oct 19, 2000 at 14:24 UTC
    Modules:
    • DBI
    • DBD::ODBC

    You can get them from:
    CPAN

Re: How do I connect to Microsoft SQL server 6.5?
by infoninja (Friar) on Oct 19, 2000 at 16:17 UTC
    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.
Re: How do I connect to Microsoft SQL server 6.5?
by Caillte (Friar) on Oct 19, 2000 at 19:39 UTC
    The DBI module is not fun for the uninitiated... have a read here for some good tutorials.
Re: How do I connect to Microsoft SQL server 6.5?
by Caillte (Friar) on Oct 19, 2000 at 19:48 UTC
    Oops... I did, of course, men read this instead. (I hope ;))

    Originally posted as a Categorized Answer.

Re: How do I connect to Microsoft SQL server 6.5?
by Anonymous Monk on Mar 31, 2004 at 21:09 UTC
    sd

    Originally posted as a Categorized Answer.

A reply falls below the community's threshold of quality. You may see it by logging in.