All Forums >> [Scripting] >> ASP >> Help connecting to Access DB Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Hi I'm following a tutorial on ASP using VBSCRIPT and have typed up the example code which should connect to my database, retrieve information, then display it on the page. Unfortunately it's not working for me, I am getting a page cannot be displayed error, along with the following:
"Error Type: Microsoft VBScript compilation (0x800A03EA) Syntax error /mick/test/databasecon.asp, line 5, column 58".
I really can't work out what the problem is. Can anyone here help me? The only thing I've done differently to the example code (demo files aren't provided with my tutorial) is to use my own access database file and refer to tables and fields within that. NB My database is stored in the root directory of my site (if you can call it that at this stage).
Here's my code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<%@LANGUAGE="VBSCRIPT"%>
<%Set Conn=Server.CreateObject("ADODB.Connection") Conn.Open"DRIVER={Microsoft Access Driver (*.mdb)}; DBQ="&_Server.MapPath("db1.mdb") SQL="select Customer Name,JSH Design Number from Worksheet" set RSworksheet = Conn.execute (SQL)%>
<html> <head> <title>Connect to Database</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head>
Dear Basil the Fox, There r some mistakes, so i will give u the complete correct code. PLZ Note that it is a bit diffrent from urs. And i personaly recommend u to use my way since u r a biggener:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<%@LANGUAGE="VBSCRIPT"%>
<% Dim Conn Dim RSworksheet
Set Conn=Server.CreateObject("ADODB.Connection") Conn.ConnectionString ="Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & Server.MapPath("/db1.mdb") Conn.Open Conn.BeginTrans set RSworksheet = server.CreateObject("ADODB.Recordset") set RSworksheet.ActiveConnection =Conn objCon.CommitTrans objRs.Open "SELECT Customer Name,JSH Design Number FROM Worksheet",Conn,2,3 %>
<html> <head> <title>Connect to Database</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head>