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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Connecting to Access DB via ASP (DSN-Less)

Status
Not open for further replies.

sugarflux

Technical User
Aug 14, 2003
111
0
0
GB
Hi all

Been programming with VB for years but fairly new to ASP. I have created a MSAccess database in the root of my webspace (lets call it DB1.mdb) and a table called P with fields PID, PForename, PSurname.

I've created the following as QueryDB.html:

<html>
<body>
<%

DSN="PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & server.mappath("DB1.mdb") & ";"

Set dbconn = server.createobject("ADODB.Connection")
objconn.open DSN
strsql = "SELECT * FROM P"
set rst = objconn.execute(strsql)
Do while not rst.eof
response.write rst("PForename") & <p>
rst.movenext
loop
rst.close
set rst = nothing
objconn.close
set objconn = nothing
%>
</body>
</html>

I'm getting absolutely nowhere. The above is not connecting to /finding the database. I've tried replacing the DSN line with:
DSN="DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & server.mappath("DB1.mdb") & ";"

Can anyone give me a clue as to where i'm going wrong please?? (My webspace is with 1and1.co.uk if that's important?)

Thanks

sugarflux
 
This is what I use and it works:

<%@ Language=VBScript %>
<%Option explicit
Dim oRs, oConn, connect, strSQL

set oConn=server.CreateObject ("adodb.connection")
connect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &_
Server.MapPath("db/mydb.mdb") & ";Persist Security Info=False"
oConn.Open connect
%>

<%
Set oRS = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT * FROM tblGroups WHERE [Active]=true and [GroupName] like '%" & Request.Form("SearchValue") & "%' ORDER BY [GroupNumber]"
oRS.CursorType = 2
oRS.LockType = 3
oRs.Open strSQL, oConn
Do while not oRs.EOF

Response.Write"<table cellpadding=0 cellspacing=1 border=1 bordercolor=#FFFFFF bgcolor=#EAEAEA width='100%'>"
Response.Write"<tr>" ....etc etc.

oRs.MoveNext
loop
oRS.Close
Set oRS = Nothing
oConn.Close
set oConn = Nothing
Response.Write"</table>"
%>

Hope this helps.


:)WB
 
Thanks guys.. I've researched and i've been a bit stupid. The package i have with 1and1 doesn't support ASP. In fact - doesn't support any scripting at all.

This will explain my frustrations!

Guess it's time to upgrade. Sorry for wasting your time

sugarflux
 
You will need to get the MS Package from 1and1 as you are not upgrading but really side grading. By default they give you the Linux package. I have several sites that are hosted on 1and1.

Make sure your site is backed up before you make the move.



:)WB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top