Mariner
11-27-2005, 10:12 AM
Could someone help me with how to connect to a MS Access Database using Perl.
I have been using the following code for when the database is on my hard drive:
#! C:\perl\bin\perl
use Win32::OLE;
use Win32::OLE::Const 'Microsoft ActiveX Data Objects';
$table = "tablename";
$conn = Win32::OLE->new("ADODB.Connection");
$rs = Win32::OLE->new("ADODB.Recordset");
$conn->Open("DBname");
but now i have uploaded the db to the web host server and seem unable to give the database a DSN to enable this code to work as ODBC only lets me name dbs on my hard drive.
Alternatively i think i could use :
use DBI;
$dbh = DBI->connect( );
but i dont know what exactly to put in the ( )! :confused:
Any help much appreciated!
I have a store I built and put it on a free server for testing and it works like a charm on the freebie g.1asphost.com/westernscientific. I uploaded the same files to my paid server (dts-net.com on a Windows 2003)westernscientific.net and when you attempt to add a product to the shopping cart it returns a server error. My hosting company insist it is not a server side error. Can someone help me make this thing work. I have tried everything I could possible think of.
This is the code for the add to cart.asp page:
<%@ Language=VBScript %>
<% pageTitle = "Add To Cart" %>
<!-- #include file="db.asp" -->
<!-- #include file="adovbs.inc" -->
<%
Sub CreateNewOrder()
Application.lock
if Application("orderID") = "" then
Application("orderID") = 1
end if
intOrderID = Application("orderID")
Session("orderID") = intOrderID
Conn.Execute("INSERT INTO orders " _
& " (orderID, status) values " _
& " ("&intOrderID&", 'OPEN')")
Application("orderID") = Application("orderID") + 1
Application.Unlock
End Sub
Sub AddToOrder(nOrderID, nProductID, nQuant)
sqlText = "INSERT INTO itemsOrdered " _
& " (orderID, productID, quantity) values " _
& " ("&nOrderID&", "&nProductID&", "&nQuant&")"
Conn.Execute(sqlText)
End Sub
'Main program
intProdID = Request.form("intProdID")
intQuant = Request.form("intQuant")
set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open ConString
intOrderID = cstr(Session("orderID"))
if intOrderID = "" then
CreateNewOrder
end if
sqlText = "SELECT * FROM itemsOrdered WHERE orderID =" & intOrderID & "AND productID =" & intProdID
set rsOrder = Conn.Execute(sqlText)
if rsOrder.EOF then
txtInfo = "This item has been added to your order."
AddToOrder intOrderID, intProdID, intQuant
else
txtInfo = "This item is already in your cart."
end if
%>
This is the code for the global.asa page:
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Application_OnStart
'==Visual InterDev Generated - startspan==
'-- Project Data Environment
'Set DE = Server.CreateObject("DERuntime.DERuntime")
'Application("DE") = DE.Load(Server.MapPath "Global.ASA"), "_private/DataEnvironment/DataEnvironment.asa")
'==Visual InterDev Generated - endspan==
Dim vPath, pPath, ConString
vPath = "database\metacart.mdb"
pPath = Server.MapPath( vPath )
ConString = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & pPath & ";" & "JET OLEDB"
Application("visits") = 0
Application("Active") = 0
set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open ConString
set rsMaxOrder = Conn.Execute("select orderID from" _
& " orders " & "order by orderID desc")
if rsMaxOrder.EOF then
Application("orderID") = 1
else
Application("orderID") = rsMaxOrder("orderID") + 1
end if
rsMaxOrder.Close
set rsMaxOrder = Nothing
Conn.Close
set Conn = Nothing
End Sub
Sub Session_OnStart
Session("Start") = Now
Application.lock
Application("visits") = Application("visits") + 1
intTotal_visitors = Application("visits")
Application.unlock
Session("VisitorID") = intTotal_visitors
Application.lock
Application("Active") = Application("Active") + 1
Application.unlock
End Sub
Sub Session_OnEnd
Application.lock
Application("Active") = Application("Active") - 1
Application.unlock
End Sub
</SCRIPT>
This is the code for the db.asp file:
<%
Dim vPath, pPath, ConString
vPath = "database\metacart.mdb"
pPath = Server.MapPath( vPath )
ConString = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & pPath & ";" & "JET OLEDB:Database Password="
%>
My database is located inside of a folder inside of the root directory on the server.
This is the error message I get from the server when you click on the add to cart button......
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator to inform of the time the error occurred and of anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
--------------------------------------------------------------------------------
Web Server at westernscientific.net