Results 1 to 11 of 11
  1. #1
    Join Date
    Dec 2003
    Location
    Brisbane
    Posts
    14

    Red face Unanswered: 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
    ############################

  2. #2
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    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.

  3. #3
    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 01:11.

  4. #4
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    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??

  5. #5
    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
    %>

  6. #6
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    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?

  7. #7
    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!!!

  8. #8
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    Could be,.. I have never used SunOne ASP. How does it different from standard asp?

  9. #9
    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.

    Originally posted by rokslide
    Could be,.. I have never used SunOne ASP. How does it different from standard asp?

  10. #10
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    Does it use the standard MDAC components or does it use some sort of "copy" to do what MDAC does?

  11. #11
    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).


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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •