Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ODBC Error

Status
Not open for further replies.

bknox

Technical User
Apr 13, 2004
30
0
0
US
I have created a System DSN for the file I wish to open. However, whenever I move to another script to handle other processing tasks, it gives me the following error:

couldn't open Purchase Order DB: po because -1032[Microsoft][ODBC Microsoft Access Driver] The Microsoft Jet database engine cannot open the file '(unknown)'. It is already opened exclusively by another user, or you need permission to view its data.</br> at C:/Perl/lib/functions.lib line 7.

I have closed the connection to the database from script1 by using the $db->close() method. However when I go to connect to the DB again it gives me this error. The code contained within the functions.lib is the following:

sub connecttodsn
{

$DSN = "po";

#Connect to PO DB
$_[0]=new Win32::ODBC($DSN) or die "couldn't open Purchase Order DB: $DSN because ", Win32::ODBC::Error(), "</br>";
}
1;

Help please:

Ben
 
Ben,

Have you got the access database open in MS Access?

--Paul
 
No Sir. I just have the Web program running in IE.
 
I've never used this module before so I could be wrong...

1) I'm not sure that $_[0] is a valid assignment, unless it's a callback? This might be a probelm (~shrug~ Dunno)

2) The Access Error string is saying 'unknown', so it looks like the value po isn't getting passed, check the DSN po on the machine where the script is run.

HTH
--Paul

 
$_[0] indicates the first value passed to the subroutine. I call it with connecttodsn($db) so $_[0] is a reference to $db. I am not sure what you mean by check the po on the machine. It is working, b/c I can use it in one script just not in another. I get the same error message even if I create another DSN and use it instead of po.

Ben
 
check the po-simply check the DSN to make sure it exists.

$_[0]- you're assigning a new instance of the ODBC object to a variable that was passed to the subroutine connecttotdsn - this doesn't sound right

Can you post the code that works?

--Paul
 
Here you go Paul:

Script1:

#!c:\Perl\bin\perl.exe -w
use Win32::ODBC;
use CGI ':standard';
use CGI::Carp qw(fatalsToBrowser);

require 'functions.lib';

print "content-type: text/html \n\n";

$db;

connecttodsn($db);
#############################################################################################################################
print <<EOF;
<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Employee</title>
<script language="javascript" type="text/javascript">
function validate(form)
{
if(form.employee.selectedIndex == 0)
{
alert("You must enter a valid Employee")
return false
}
if(form.vendor.selectedIndex == 0)
{
alert("You must enter a valid Vendor")
return false
}
if(form.salesTax.value == "")
{
alert("You must enter a sales tax rate")
return false
}
return true
}

</script>

</head>

<body>
<p align="center"><font size="6">Purchase Order Form</font></p>

<form name="POForm" method="POST" onsubmit="return validate(this)" action="../../Scripts/shipInfo.pl">
EOF
##########################################################################################################################

#########################################################################################################################

print <<EOF;
<p>Employee: <select size="1" name="employee"><option value="SelectFromBelow">Select From Below</option>
EOF
#############################################################################################################################

$sqlstmnt = "SELECT firstName, lastName FROM employees ORDER BY lastname ASC";
$db->Sql("$sqlstmnt");

while ($db->FetchRow)
{
my ($fname, $lname) = $db->Data();
print "<option value='$lname, $fname'>$lname, $fname</option>";
}

my @date = localtime;
$year = $date[5] + 1900;
$month = $date[4] +1;
$todayDate = "$month.$date[3].$year";

#############################################################################################################################
print <<EOF;
</select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Date: <input type="text" name="date" size="10" value="$todayDate">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Quote Ref. #: <input type="text" name="quoteNum" size="10"></p>
<p>Vendor: <select size="1" name="vendor"><option value="SelectFromBelow">Select From Below</option>
EOF
#############################################################################################################################

$sqlstmnt = "SELECT CompanyName FROM Vendors ORDER BY CompanyName";

$db->Sql("$sqlstmnt");

while ($db->FetchRow)
{
my ($vname) = $db->Data();
print "<option value='$vname'>$vname</option>";
}

#Close PO DB connnection
$db->Close();
#########################################################################################################################
print <<EOF;
</select>&nbsp;&nbsp;&nbsp;&nbsp;</p>
<p>Freight Charge: <input type="input" name="fc" size="10">&nbsp;&nbsp;&nbsp;&nbsp;Sales Tax (Decimal Form): <input type="text" name="salesTax" size="10">&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="Next" name="addLI"></p>

</form>
</body>
</html>
EOF
#########################################################################################################################


Functions.lib:

sub connecttodsn
{
$DSN = "po";
$_[0] = new Win32::ODBC($DSN);
}
1;

shipInfo.pl:

sub connecttodsn
{
$DSN = "po";
$_[0] = new Win32::ODBC($DSN);
}
1;
 
correction:

shipInfo.pl:

#!c:\Perl\bin\perl.exe -w
use Win32::ODBC;
use CGI ':standard';
use CGI::Carp qw(fatalsToBrowser);


require 'functions.lib';

print "content-type: text/html \n\n";

$db;

connecttodsn($db);

print "In Script";

$db->close();
 
Tell me about your configuration(s)

Does it work okay in test, but not in production?

--Paul

PS-It's a bit l8 my side o de world
 
It is not in production yet, so it is not working in testing stages. I have set up a DSN through XP under the admistrator tools within the control panel. It is a System DSN with a Access driver being used, and named po. I have the latest version of active perl installed, and are running the web pages on my local machine via IIS. If you need anything else let me know.

Ben
 
I don't understand please clairfy.

Guninees Over IP?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top