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
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:
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
Outside of code tags, you may need to use entities for some characters:
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|