ASP - Connecting to MS Access DB, Where am i going wrong!

Associate
Joined
12 Aug 2004
Posts
1,009
Location
Glasgow, Scotland
Hi there,

Trying to connect to an MS Access database using classic ASP and i can't seem to produce any results :confused:, i'm going by the book and it just doesn't want to work...

All the names for the database and DSN connection seem to spelt correctly, there must be something to do with the ASP syntax that i'm missing :confusing:

Thanks for any help :)

Error Message
Error Type:
Microsoft VBScript runtime (0x800A01C2)
Wrong number of arguments or invalid property assignment
Website/index.asp, line 55

DatabaseConnect.asp
Code:
<%
	Dim objConn
	Set objConn = Server.CreateObject("ADODB.Connection")
	objConn.ConnectionString = "DSN=littercode_cms"
	objConn.Open
%>

index.asp
Code:
<%@ Language=VBScript %>
<%  Option Explicit %>
<!--#include file="Connections/DatabaseConnect.asp"-->
<%
	Const adOpenForwardOnly = 0
	Const adLockOptimistic = 3
	Const adLockPessimistic = 2
	Const adLockReadOnly = 1
	Const adCmdTable = 2
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
		<meta name="description" content="insert variable for website description here" />
		<meta name="keywords" content="insert variable for website keywords" />
		<title>Untitled</title>
		<link rel="stylesheet" type="text/css" title="default" href="styles.css">

		<script language="JavaScript1.2" type="text/javascript">
			function clearDefault(el)
			{
				if (el.defaultValue==el.value) el.value = ""
			}
		</script>
	</head>
	
	<body>
		<div id="header"></div>
		<div id="wrapper">
			<div id="logoheader">
				<div id="logoheaderleft">
					<h1>Test Header</h1>
				</div>
				<div id="logoheaderright">
					<div id="logoheaderlinks">
						<a href="#" title="">Home</a> &nbsp;&nbsp;
						<a href="#" title="">About</a> &nbsp;&nbsp;
						<a href="#" title="">Sitemap</a> &nbsp;&nbsp;
						<a href="#" title="">Contact</a>
					</div>
					<div id="search-textonly">
					</div>
				</div>
			</div><!-- end of logoheader-->
			<div id="navheader">
				<%
					Dim objRS
					Set objRS = Server.CreateObject ("ADODB.Recordset")
					objRS.Open "tblMenu", objConn, , , adCmdTable
				%>
				<ul>
					<%Do While Not objRS.EOF%>
						<li><a href="index.asp?pg=<%objRS("IntLinkAddress")%>" title="<%objRS("Name")%>"%>><%objRS("Name")%></a></li>
						<%objRS.MoveNext%>
					<%Loop
						'closing the recordset connection
						objRS.Close
						Set objRS = Nothing
					%>
				</ul>
			</div><!-- end of navheader -->
			<div id="navlower">
				<form action="" method="post" name="search" class="searchform">
					<input type="text" name="search" value="Start new search" onfocus="javascript:clearDefault(this)" class="searchinput" /><input type="submit" name="searchs" id="" class="searchsubmit" value="Go" />
				</form>
				<a href="#" title="Text-only" class="textonly">Text-only</a>
			</div>
			<div id="leftcol">
				<ul>
					<li><a href="#">Sub Section 3</a></li>
					<li><a href="#">Sub Section 3</a></li>
					<li><a href="#">Sub Section 3</a></li>
					<li><a href="#">Sub Section 3</a></li>
					<li><a href="#">Sub Section 3</a></li>
					<li><a href="#">Sub Section 3</a></li>
					<li><a href="#">Sub Section 3</a></li>
					<li><a href="#">Sub Section 3</a></li>
					<li><a href="#">Sub Section 3</a></li>
				</ul>
			</div>
			<div id="rightcol">

			</div>
			<div id="footer">footer test</div>
		</div><!-- end of #wrapper -->
	</body>
</html>

<%
	'close the dsn connection
	objConn.Close
	Set objConn = Nothing
%>
 
anyone? :( ... i'm using MS Access 97 if that helps, not sure how compatible it is as its the old database format.
 
Noticed a problem on line 55.
Code:
<a href="index.asp?pg=<%objRS("IntLinkAddress")%>" title="<%objRS("Name")%>"[COLOR=Red]%>[/COLOR]><%objRS("Name")%></a>
That %> shouldn't be there. Not sure if that would give that sort of error though.

Take it out and try again?

Edit: also try adding <% on error resume next %> will let you see how much parses, instead of spitting an unhelpful error at you.
 
Last edited:
try :

PHP:
objRS.Open "tblMenu", objConn, adOpenForwardOnly,adLockReadOnly, adCmdTable
or
PHP:
objRS.Open "select * from tblMenu", objConn, adOpenForwardOnly,adLockReadOnly, adCmdTable

instead of
PHP:
objRS.Open "tblMenu", objConn, , , adCmdTable

when you open the record set. Not 100% sure if it will help, but worth a try.

akakjs
 
assuming you're not getting any errors from your database connection, try this...

you have:
<li><a href="index.asp?pg=<%objRS("IntLinkAddress")%>" title="<%objRS("Name")%>"%>><%objRS("Name")%></a></li>

you need:
<li><a href="index.asp?pg=<%= objRS("IntLinkAddress") %>" title="<%= objRS("Name") %>"><%= objRS("Name") %></a></li>

the <%= ... %> denotes a response.write, whereas <% ... %> is just a block of code to be executed.

HTH
 
Yeah, just asked my boss and he said the exact same thing, and also showed me a few shortcuts to use when opening the dsn connection and record sets :)

Thanks for the help :)
 
Isn't using a DSN-less connection far less secure?, as it provides direct access to the database.
 
topbanana said:
Why are you still using ASP?
Quite a few companies will have legacy systems that are still running applications that are too large to be easily replaced by newer code, or running NT servers that can't handle .net.

Sadly enough, I have to support a critical piece of stock management software that is classic asp-based, it's a real nightmare but there isn't any time to re-write it in .net despite my numerous protestations to the boss :(

I also am (again, against my will) just bringing in a mahoosive classic asp-based CRM system to replace an even older thick-client system - I hate it and the fact that I'm having to implement a long-term asp-based solution really bites.. but the bosses are governed by the guys in the US who pay the wages :(
 
Sadly enough, I have to support a critical piece of stock management software that is classic asp-based, it's a real nightmare but there isn't any time to re-write it in .net despite my numerous protestations to the boss
I run a whole website like that... we're looking at 3000-4000 man hours to convert it... Tis painful..

akakjs
 
riddlermarc said:
Sadly enough, I have to support a critical piece of stock management software that is classic asp-based, it's a real nightmare but there isn't any time to re-write it in .net despite my numerous protestations to the boss :(
That's a pain. You could always write the new pages in .Net? You would need to work out state sharing but it's not beyond the wit of man.
 
Back
Top Bottom