Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
peacemaker1820, I had to include the IP address, Port number, and the domain\server in order to get the MS SQL to work.

Check to make sure that you have current modules as well...
PPM>install DBI PPM>install DBD-ODBC

Here is some sample code to show you what works for my environment (W2K) but it should be similar (if not identical.)

#!/usr/bin/perl -w use strict; use DBI; print "Content-type: text/html\n\n"; # Set up variables for the connection my $server_name = 'domain\server'; my $server_ip = '1.2.3.4:port'; my $database_name = 'Tim'; my $database_user = 'Taylor'; my $database_pass = 'toolman'; my $DSN = 'driver={SQL Server};server=$server_name;tcpip=$server_ip;da +tabase=$database_name;uid=$database_user;pwd=$database_pass;'; my $dbh = DBI->connect("dbi:ODBC:$DSN") || die "Couldn't open database +: $DBI::errstr\n"; # Prepare the SQL query for execution my $SQL1 = $dbh->prepare(<<End_SQL) || die "Couldn't prepare statement +: $DBI::errstr\n"; select * FROM Test_Table End_SQL print '<table border="0" width="100%" cellpadding="0" cellspacing="0" +bgcolor="#ffffff" summary=""><tr><td align="center">'; print '<table border="1" cellpadding="5" cellspacing="0" bgcolor="#fff +fff" summary="">'; # Execute the query $SQL1->execute() || die "Couldn't execute statement: $DBI::errstr\n"; # Fetch each row and print it while ( my ($field1,$field2,$field3,$field4,$field5) = $SQL1->fetchrow +_array() ) { print "<tr><td>$field1</td><td>$field2</td><td>$field3</td><td>$f +ield4</td><td>$field5</td></tr>"; } print "</table></td></tr></table>"; # Disconnect from the database $dbh->disconnect();

Also, make sure that you use:
#!/usr/bin/perl -w use strict;
Use the search at the top for additional help on those and other topics (it's been discussed numerous times.) Also see the node: How to RTFM it's a really good insite to finding Perl help.
HTH

- Mission Updated: fixed my typos (again.)

In reply to Re: connecting Perl with MS SQL Server on NT using ODBC by Mission
in thread connecting Perl with MS SQL Server on NT using ODBC by peacemaker1820

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!
  • 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:
    & &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 perusing the Monastery: (4)
    As of 2014-09-16 01:02 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite cookbook is:










      Results (155 votes), past polls