josgood
asked on
Perl beginner - perhaps you forgot to load "DBI"
I'm not a Perl programmer and have inherited a Perl script. I've seen this script run on another machine, so it works and I'd expect any issues running it on my machine to be configuration ones.
When I run the script I get "Can't locate object method "connect" via package "DBI" (perhaps you forgot to load "DBI")
I'm running EPIC under Eclipse on Windows XP.
Checking with the PPM (Perl Package Manager), I see that DBI is present three times:
Package Area Installed Available
DBI site 1.604 1.602
DBI perl 1.601 (blank)
DBI (blank) (blank) 1.604
What is my problem and how can I correct it?
Thank you.
When I run the script I get "Can't locate object method "connect" via package "DBI" (perhaps you forgot to load "DBI")
I'm running EPIC under Eclipse on Windows XP.
Checking with the PPM (Perl Package Manager), I see that DBI is present three times:
Package Area Installed Available
DBI site 1.604 1.602
DBI perl 1.601 (blank)
DBI (blank) (blank) 1.604
What is my problem and how can I correct it?
Thank you.
ASKER
Here is the line that encounters the problem
#DBD::ODBC driver must be installed prior to try to connect
$g_dbh = DBI->connect('DBI:ODBC:dri ver=micros oft access driver (*.mdb);dbq='."$database", '', '')
or die ("Could not connect");
#DBD::ODBC driver must be installed prior to try to connect
$g_dbh = DBI->connect('DBI:ODBC:dri
or die ("Could not connect");
Do you have this line prior to trying to connect?
use DBI;
use DBI;
ASKER
No. use DBI; is not present.
When I add that line, the script simply terminates.
That has to indicate a problem....
I've seen this script run on the original developer's machine. I believe I have a configuration problem on mine.
A post on another URL suggested that @inc may not have the correct path. The same post suggested "which perl" to find the correct path.
I tried running "which perl" in the immediate window, but I can't see how to run a command there.
When I add that line, the script simply terminates.
That has to indicate a problem....
I've seen this script run on the original developer's machine. I believe I have a configuration problem on mine.
A post on another URL suggested that @inc may not have the correct path. The same post suggested "which perl" to find the correct path.
I tried running "which perl" in the immediate window, but I can't see how to run a command there.
Your original error would indicate that the script is executing, so you either have the correct path to perl in the shebang line or the web server is configured to locate it for you.
You definitely need to have that use statement. Since the terminates with its usage, then that would indicate that the DBI module may not be installed correctly. Can you show us a more complete sample of your code as well as the error message(s) in the web server error log?
You definitely need to have that use statement. Since the terminates with its usage, then that would indicate that the DBI module may not be installed correctly. Can you show us a more complete sample of your code as well as the error message(s) in the web server error log?
Which web server are you using?
One method to verify if the DBI module is installed and Perl can "see" it is to run this command from the XP command prompt.
perl -MDBI -e 1
No output means success, If you receive any output, then the DBI module needs to be reinstalled.
One method to verify if the DBI module is installed and Perl can "see" it is to run this command from the XP command prompt.
perl -MDBI -e 1
No output means success, If you receive any output, then the DBI module needs to be reinstalled.
If this is not a cgi script, then ignore my request for the web server error log entries.
If the script terminates when you include the use DBI; statement but doesn't produce any error message, then the module is probably installed correctly and your script is "dying" prior to the connect statement. Seeing you code will help us to help you.
If the script terminates when you include the use DBI; statement but doesn't produce any error message, then the module is probably installed correctly and your script is "dying" prior to the connect statement. Seeing you code will help us to help you.
ASKER
>>Which web server are you using?
This script is running locally. No web server is involved.
>>perl -MDBI -e 1
There was no output. Here are the lines from the command window
E:\Perl\bin>perl -MDBI -e 1
E:\Perl\bin>
The file that encounters the problem is called CRStatisticsConfiguration. pm. It contains lines such as
$database = 'D:\InternalProjects\CR Metrics\CRScripts\s5DataBa se.mdb'
along with several other variable definitions, followed immediately by
#DBD::ODBC driver must be installed prior to try to connect
$g_dbh = DBI->connect('DBI:ODBC:dri ver=micros oft access driver (*.mdb);dbq='."$database", '', '')
or die ("Could not connect");
Am I correct in thinking that this runs before the first line in my .pl file? The .pl file has a use DBI;
CRStatisticsConfiguration. pm has only a use Cwd;
This script is running locally. No web server is involved.
>>perl -MDBI -e 1
There was no output. Here are the lines from the command window
E:\Perl\bin>perl -MDBI -e 1
E:\Perl\bin>
The file that encounters the problem is called CRStatisticsConfiguration.
$database = 'D:\InternalProjects\CR Metrics\CRScripts\s5DataBa
along with several other variable definitions, followed immediately by
#DBD::ODBC driver must be installed prior to try to connect
$g_dbh = DBI->connect('DBI:ODBC:dri
or die ("Could not connect");
Am I correct in thinking that this runs before the first line in my .pl file? The .pl file has a use DBI;
CRStatisticsConfiguration.
ASKER
Here is an edited copy of the .pm file -- I've removed comments and data definitions that don't apply. I'm trying to minimize the amount of text you have to wade through.
use Cwd;
# (commentary deleted)
$database = 'D:\InternalProjects\CR Metrics\CRScripts\s5DataBa se.mdb';
# ( other data definitions deleted)
#DBD::ODBC driver must be installed prior to try to connect
$g_dbh = DBI->connect('DBI:ODBC:dri ver=micros oft access driver (*.mdb);dbq='."$database", '', '')
or die ("Could not connect");
use Cwd;
# (commentary deleted)
$database = 'D:\InternalProjects\CR Metrics\CRScripts\s5DataBa
# ( other data definitions deleted)
#DBD::ODBC driver must be installed prior to try to connect
$g_dbh = DBI->connect('DBI:ODBC:dri
or die ("Could not connect");
ASKER
I have demonstrated that the .pm file runs before the first line of the .pl file by placing a breakpoint on the first executable line of the .pl file. That breakpoint was not hit.
use Cwd;
use DBI;
use DBD::ODBC;
use Time::Local;
use DateTime::Format::Excel;
use CRStatisticsConfiguration;
use CRStatisticsFunctions;
use Win32;
# (commentary deleted)
# (breakpoint here was not hit)
$menuID = Win32::MsgBox("Please make sure any opened Excel spreadsheets are closed before running this script!!\n" .
"This script makes use of Excel. Therefore, do not run Excel till this script completes.\n" .
"\t\t\tContinue?",1|MB_ICO NEXCLAMATI ON,"Change Request Statistic Script");
use Cwd;
use DBI;
use DBD::ODBC;
use Time::Local;
use DateTime::Format::Excel;
use CRStatisticsConfiguration;
use CRStatisticsFunctions;
use Win32;
# (commentary deleted)
# (breakpoint here was not hit)
$menuID = Win32::MsgBox("Please make sure any opened Excel spreadsheets are closed before running this script!!\n" .
"This script makes use of Excel. Therefore, do not run Excel till this script completes.\n" .
"\t\t\tContinue?",1|MB_ICO
Add the use DBI; statement to the CRStatisticsConfiguration. pm module.
ASKER
OK. I just did that. This is what I tried to do in the first place.
I got the same result as before, which is that the Debug pane shows
(camel) <terminated>CRStatisticsCo nfiguratio n.pm(15)[P erl Local]
(icon)<terminated>Perl Interpreter
(icon)<terminated, exit value:0>Perl Interpreter
I don't get the "perhaps you forgot to load DBI" message, though.
The console window shows, as text below the tab but not in the clear window,
<terminated> CRStatisticsConfiguration. pm(17)[Per l Local]Perl Interpreter
Line 17 of CRStatisticsConfiguration. pm, is a blank comment line, as in
#
I appreciate your help on this...I'm not used to being this lost.
I got the same result as before, which is that the Debug pane shows
(camel) <terminated>CRStatisticsCo
(icon)<terminated>Perl Interpreter
(icon)<terminated, exit value:0>Perl Interpreter
I don't get the "perhaps you forgot to load DBI" message, though.
The console window shows, as text below the tab but not in the clear window,
<terminated> CRStatisticsConfiguration.
Line 17 of CRStatisticsConfiguration.
#
I appreciate your help on this...I'm not used to being this lost.
It's a two part system -- you need the interface (DBI) module installed, and you also need the database driver (DBD) installed (see http://search.cpan.org/~mjevans/DBD-ODBC-1.17/ODBC.pm).
You checked for the presence of the DBI module, but do you have the driver installed?
Also, though I don't use MS Access, your call to load the driver ("DBI:ODBC:driver=microsof t access driver (*.mdb);") looks a little strange... Could there be an alias or symbolic link on your developer's machine that you don't have on the problematic machine?
You checked for the presence of the DBI module, but do you have the driver installed?
Also, though I don't use MS Access, your call to load the driver ("DBI:ODBC:driver=microsof
ASKER
I have the ODBC driver installed, as shown in the attached zip file.
>>microsoft access driver (*.mdb)
This name is specified...I don't belief case is relevant.
upload.zip
>>microsoft access driver (*.mdb)
This name is specified...I don't belief case is relevant.
upload.zip
The connect string is correct for accessing an access db.
The print screens you have show that the OS is configured to connect using ODBC, but that's only half of what you need. You also need the DBD::ODBC Perl module, which is Perl's database driver needed to access a datasource via ODBC.
Run this test, like you did for the DBI module.
perl -MDBD::ODBC -e 1
The print screens you have show that the OS is configured to connect using ODBC, but that's only half of what you need. You also need the DBD::ODBC Perl module, which is Perl's database driver needed to access a datasource via ODBC.
Run this test, like you did for the DBI module.
perl -MDBD::ODBC -e 1
ASKER
I ran the test and there was no output
E:\Perl\bin>perl -MDBD::ODBC -e 1
E:\Perl\bin>
One thing that could be tripping us up...I ran this test in a command window. I'm trying to run the script from Eclipse.
I tried running the script from the command window, as in
E:\Perl\bin>d:
D:\>cd D:\InternalProjects\CR Metrics\CRScripts
D:\InternalProjects\CR Metrics\CRScripts>perl CRStatistics.pl
and the script started to run.
That tells me I have something misconfigured in Eclipse, doesn't it?
E:\Perl\bin>perl -MDBD::ODBC -e 1
E:\Perl\bin>
One thing that could be tripping us up...I ran this test in a command window. I'm trying to run the script from Eclipse.
I tried running the script from the command window, as in
E:\Perl\bin>d:
D:\>cd D:\InternalProjects\CR Metrics\CRScripts
D:\InternalProjects\CR Metrics\CRScripts>perl CRStatistics.pl
and the script started to run.
That tells me I have something misconfigured in Eclipse, doesn't it?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If they're not already included, you should add the following 2 pragmas to your script(s).
use warnings;
use strict;
Those 2 pragmas should be in EVERY Perl script (and module) that you write but beware, if the scripts weren't properly written, the strict pragma could "break" your scripts even more than they already are broken.
use warnings;
use strict;
Those 2 pragmas should be in EVERY Perl script (and module) that you write but beware, if the scripts weren't properly written, the strict pragma could "break" your scripts even more than they already are broken.
ASKER
I think you've answered my question about as well as it can be answered, so I'm going to close it and will open another if I have followup questions.
>>receive any warnings or errors when you ran: D:\InternalProjects\CR Metrics\CRScripts>perl CRStatistics.pl
No. I've just started it again and it seems to be running fine.
>>makes use of the DBI module's method calls without loading the DBI module
I don't know Perl, but if loading the module is a requirement, then I'm surprised it runs at all without loading it. Perhaps we're getting away with this because the main .pl script *does* use DBI. A confusing point and I get the feeling I'll be coming back to it.
Thank you for your help and your patience. I'm sure I'll be seeing you on other questions.
Joe
>>receive any warnings or errors when you ran: D:\InternalProjects\CR Metrics\CRScripts>perl CRStatistics.pl
No. I've just started it again and it seems to be running fine.
>>makes use of the DBI module's method calls without loading the DBI module
I don't know Perl, but if loading the module is a requirement, then I'm surprised it runs at all without loading it. Perhaps we're getting away with this because the main .pl script *does* use DBI. A confusing point and I get the feeling I'll be coming back to it.
Thank you for your help and your patience. I'm sure I'll be seeing you on other questions.
Joe
ASKER
Thank you.
$dbh = DBI->connect($dsn, $user, $password, { RaiseError => 1, AutoCommit => 0 });