Hello monks,
I need your help. I'm trying to connect to a SQL Server 2000 database and I'm having problems with it. when I run the script, it gets an error message "Can't locate method "Connect" via package "DBI" Perhaps you forgot to load DBI at line 39" Could you let me know what is it wrong in the script?? Could you give me an example how to connect to SQL Serve 2000 using DBI?? I'll appreciate your help.
#! perl -w
use strict;
use warnings;
use DBI;
# my $dir = 'K:\\reports';
# my $count = 0;
# opendir DH, $dir or die "Cannot open $dir: $!";
# while (my $file = readdir DH) {
# next unless $file =~ /\.pdf$/;
# my @newfile = substr($file,2,6);
# process_records(@newfile);
# }
# closedir DH;
my $user = "username";
my $password = "password1";
my $data_source = "dbi::SQL Server:Interfaces";
my $dbh = DBI->connect($data_source, $user, $password, {
PrintError => 1,
RaiseError => 0
} ) or die "Can't connect to $data_source: $DBI::errstr";
my $sth = $dbh->prepare( q{
SELECT *
FROM tableview
where field1 = '029622'}) or die "Can't prepare statement: $
+DBI::errstr";
my $rc = $sth->execute or die "Can't execute statement: $DBI::errstr";
print "Field names: @{ $sth->{NAME} }\n";
while (my @arr = $sth->fetchrow_array) {
print "@arr\n";
}
die $sth->errstr if $sth->err;
$dbh->disconnect;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|