If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > accessing a table from a database

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-14-04, 20:54
davep23 davep23 is offline
Registered User
 
Join Date: Dec 2003
Location: Brisbane
Posts: 14
Red face accessing a table from a database

I'm using the following script to access a table from a database but I'm getting the following error message... Can someone check over the code and see where I'm going wrong???


<% @ Language="VBScript" %>
<% Option Explicit %>
<%
Dim server.CreateObject, sConnString, connection.Open, Response.Write
server.CreateObject("ADODB.recordset")
sConnString="DSN=database1"
connection.Open "People"
Response.Write ("People").Value
%>

########################
ERROR MESSAGE
Sun ONE ASP VBScript compilation (0x800A0401)
Syntax error, unexpected ".", expecting end of statement
/test.asp, line 4, column 11
############################
Reply With Quote
  #2 (permalink)  
Old 01-14-04, 22:19
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
Your code would look a lot better like this....

Code:
<% @ Language="VBScript" %>
<% Option Explicit %> 
<%
Dim PeopleRS, sConnString, myConn, mySQL
Set myConn= server.CreateObject("ADODB.Connection") 
sConnString="DSN=database1"
myConn.Open sConnString
mySQL = "Select * from People"
Set PeopleRS = myConn.Execute(mySQL)
Response.Write PeopleRS("fieldname").value
%>
The above won't work perfectly either, but it's a lot closer to what you are looking for. If you provide more details about your database and the tables and the data and exactly what you are trying to do I'm sure someone can help.
Reply With Quote
  #3 (permalink)  
Old 01-14-04, 23:53
davep23 davep23 is offline
Registered User
 
Join Date: Dec 2003
Location: Brisbane
Posts: 14
extract the contents of a table

Thanks rokslide,

What I'm after is a script which will extract the contents of a table from an access database so they are displayed on an .asp page.

Your recent contribution was way better than mine.

Perhaps you could help further with the extra info:

Database name: database1
Table name: People
The 3 fields within table include: ID, People, Comment

Cheers

<% @ Language="VBScript" %>
<% Option Explicit %>
<% Dim PeopleRS, sConnString, myConn, mySQL
Set myConn= server.CreateObject("ADODB.Connection")
sConnString="DSN=database1"
myConn.Open sConnString mySQL = "Select * from People"
Set PeopleRS = myConn.Execute(mySQL)
Response.Write PeopleRS("fieldname").value
%>

By the way... I'm still getting this error message now:
Sun ONE ASP VBScript compilation (0x800A0401)
Syntax error, unexpected "identifier", expecting end of statement
/test.asp, line 6, column 25

Last edited by davep23; 01-15-04 at 00:11.
Reply With Quote
  #4 (permalink)  
Old 01-15-04, 00:13
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
Okie, the problem you have in the code you have posted back to me is that you have joined two lines together.

Line 6 ends after sConnString, line 7 starts at mySQL.

With ASP/VBScript there is no end statement identifier (like the ; in C) so you have to be a bit more careful about when you start and end you lines...

try this code...

Code:
<% @ Language="VBScript" %>
<% Option Explicit %> 
<%
Dim PeopleRS, sConnString, myConn, mySQL
Set myConn= server.CreateObject("ADODB.Connection") 
sConnString="DSN=database1"
myConn.Open sConnString
mySQL = "Select * from People"
Set PeopleRS = myConn.Execute(mySQL)
Response.Write "<table>"
do while not PeopleRS
  Response.Write "<tr>"
  Response.Write "<td>" & PeopleRS("ID").value & "</td>"
  Response.Write "<td>" & PeopleRS("People").value & "</td>"
  Response.Write "<td>" & PeopleRS("Comment").value & "</td>"
  Response.Write "</tr>"
  PeopleRS.MoveNext
loop
Response.Write "</table>"
Set PeopleRS = nothing
Set myConn = nothing
%>
Have you set up the DSN you used above??
Reply With Quote
  #5 (permalink)  
Old 01-15-04, 00:23
davep23 davep23 is offline
Registered User
 
Join Date: Dec 2003
Location: Brisbane
Posts: 14
I've set up my DSN so that should be OK.

I tried the lastest code and I can see what you mean but now I'm getting this strange error message:

########
ADODB.Connection.1 (0x80004005)
SQLState: S1000 Native Error Code: -1045 [DataDirect][ODBC SequeLink driver][ODBC Socket][Microsoft][ODBC Microsoft Access Driver] Not a valid bookmark.
/test.asp, line 7
#########

which is: myConn.Open sConnString ???


try this code...

Code:
<% @ Language="VBScript" %>
<% Option Explicit %> 
<%
Dim PeopleRS, sConnString, myConn, mySQL
Set myConn= server.CreateObject("ADODB.Connection") 
sConnString="DSN=database1"
myConn.Open sConnString
mySQL = "Select * from People"
Set PeopleRS = myConn.Execute(mySQL)
Response.Write "<table>"
do while not PeopleRS
  Response.Write "<tr>"
  Response.Write "<td>" & PeopleRS("ID").value & "</td>"
  Response.Write "<td>" & PeopleRS("People").value & "</td>"
  Response.Write "<td>" & PeopleRS("Comment").value & "</td>"
  Response.Write "</tr>"
  PeopleRS.MoveNext
loop
Response.Write "</table>"
Set PeopleRS = nothing
Set myConn = nothing
%>
Reply With Quote
  #6 (permalink)  
Old 01-15-04, 00:31
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
Hmmm, well it's been ages since I have used a DSN or Access or ASP, but at a guess I would say that message is likely to be because of the DSN not being set up properly....

Can you do something like...

Code:
<% @ Language="VBScript" %>
<% Option Explicit %> 
<%
Dim PeopleRS, sConnString, myConn, mySQL
Set myConn= server.CreateObject("ADODB.Connection") 
sConnString="Provider=Microsoft.Jet.OLEDB.4.0;" & _
  "Data Source=\\IP_ADDRESS\MY_PATH\Database1.mdb;" & _
 "Jet OLEDB"
myConn.Open sConnString
mySQL = "Select * from People"
Set PeopleRS = myConn.Execute(mySQL)
Response.Write "<table>"
do while not PeopleRS
  Response.Write "<tr>"
  Response.Write "<td>" & PeopleRS("ID").value & "</td>"
  Response.Write "<td>" & PeopleRS("People").value & "</td>"
  Response.Write "<td>" & PeopleRS("Comment").value & "</td>"
  Response.Write "</tr>"
  PeopleRS.MoveNext
loop
Response.Write "</table>"
Set PeopleRS = nothing
Set myConn = nothing
%>
but replace IP_ADDRESS, MY_PATH so that you are pointing to the right MDB file?
Reply With Quote
  #7 (permalink)  
Old 01-15-04, 00:41
davep23 davep23 is offline
Registered User
 
Join Date: Dec 2003
Location: Brisbane
Posts: 14
Wink DSN ok

Checked DSN and it's ok.

But could it be a problem relating to SunOne ASP?

Server supplier does not support MY_PATH (DSNless) only DSN so I have to use: sConnString="DSN=database1"

Bugger!!!
Reply With Quote
  #8 (permalink)  
Old 01-15-04, 00:45
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
Could be,.. I have never used SunOne ASP. How does it different from standard asp?
Reply With Quote
  #9 (permalink)  
Old 01-15-04, 00:52
davep23 davep23 is offline
Registered User
 
Join Date: Dec 2003
Location: Brisbane
Posts: 14
Unhappy

SunOne is a Unix based server not Windows based server. SunOne is capable of treating ASP and databases like Windows but has its own complications and idiosyncrasies.

Your advice and coding has been most helpful. If you or other members come up with any other suggestions let me know.

Quote:
Originally posted by rokslide
Could be,.. I have never used SunOne ASP. How does it different from standard asp?
Reply With Quote
  #10 (permalink)  
Old 01-15-04, 00:56
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
Does it use the standard MDAC components or does it use some sort of "copy" to do what MDAC does?
Reply With Quote
  #11 (permalink)  
Old 01-15-04, 01:02
davep23 davep23 is offline
Registered User
 
Join Date: Dec 2003
Location: Brisbane
Posts: 14
Cool copy" I believe...

It uses a "copy" I believe. Other than that... ????

I know that Access can be used on Unix and SunOne and the Jet Drivers are used as with Windows Servers (except for a few changes).


Quote:
Originally posted by rokslide
Does it use the standard MDAC components or does it use some sort of "copy" to do what MDAC does?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On