Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jul 2012
    Posts
    11
    Rep Power
    0

    Connect ASP page to SQL Table


    I am completely new to ASP and I am trying to make an SQL connection from a html page to a SQL 2008 database

    database name is Exchange

    table name is Report

    Here is what I have so far but I don't get anyting when I click on the the query.html file


    <!DOCTYPE html>
    <html>
    <body>

    <h1>MS Exchange Report</h1>

    <p>Testing Phase</p>

    <%





    Dim cn
    Dim rs
    Dim sql

    Set rs=Conn.Execute(sql)


    Set cn = Server.CreateObject("ADODB.Recordset")
    "PROVIDER=SQLOLEDB;DATA SOURCE=192.168.10.10;DATABASE=Exchange;USER ID=administrator;PASSWORD=passwprd;"

    [Code]
    Set rs = Server.CreateObject("ADODB.Recordset")
    sql = "SELECT * FROM Report"

    rs.Open sql, cn

    While Not rs.EOF
    Response.Write(rs.Fields("user")
    Response.Write(rs.Fields("quantity")

    rs.MoveNext
    Loop
    %>

    </body>
    </html>
    [Code]

    Any help would be appreciated.

    Thank-you!
  2. #2
  3. Contributing User
    ASP Skiller (1500 - 1999 posts)

    Join Date
    Mar 2005
    Location
    Columbus, OH
    Posts
    1,607
    Rep Power
    278
    first at all it must be asp not html file and it should be something like that...

    Code:
    <html>
    <body>
    
    <h1>MS Exchange Report</h1>
    
    <p>Testing Phase</p>
    
    <%
    
    Dim cn
    Dim rs
    Dim sql
    
    
    Set cn = Server.CreateObject("ADODB.Recordset")
    cn.open "PROVIDER=SQLOLEDB;DATA SOURCE=192.168.10.10;DATABASE=Exchange;USER ID=administrator;PASSWORD=passwprd;"
    
    
    Set rs = Server.CreateObject("ADODB.Recordset")
    sql = "SELECT * FROM Report"
    
    rs.Open sql, cn
    
    While Not rs.EOF
    Response.Write rs("user")
    Response.Write rs("quantity")
    
    rs.MoveNext
    Loop
    
    rs.close
    cn.close
    set rs=nothing
    set cn=nothing
    %>
    
    </body>
    </html>
    GK
    __________________________________________________ _____
    if you found this post is useful click Give Rep button (bottom side on this reply ) and agree
  4. #3
  5. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jul 2012
    Posts
    11
    Rep Power
    0
    Do I save it as a .asp file and if that is the case how do I call it from the html.

    Thanks.
  6. #4
  7. Contributing User
    ASP Skiller (1500 - 1999 posts)

    Join Date
    Mar 2005
    Location
    Columbus, OH
    Posts
    1,607
    Rep Power
    278
    Why you need to call from html? Save as test.asp and call
    http://yourDomainName/test.asp
  8. #5
  9. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jul 2012
    Posts
    11
    Rep Power
    0
    When I save it as you suggested but I called it query2.asp

    I have IIS pointing to the folder f:\web and the file iside that folder i enter into the web browser on the same machine

    http://localhost/query2.asp

    I get page not found - If I rename it to query2.html

    It does display the html section of the file.

    Cleary ISS is finding it but the asp code is not working for some reason.

    Any ideas?

    Thanks again.
  10. #6
  11. Contributing User
    ASP Skiller (1500 - 1999 posts)

    Join Date
    Mar 2005
    Location
    Columbus, OH
    Posts
    1,607
    Rep Power
    278
    check you iis settings by default is it not processes asp pages only html is enabled by default
  12. #7
  13. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jul 2012
    Posts
    11
    Rep Power
    0
    You were right it was disabled but it still doesn't work after enabling it.

    http://localhost/query.asp

    - cannot display web page.

    When I change the extension to query.html

    It at least shows the html section/title of the page.

    Any more ideas?

    Thanks.
  14. #8
  15. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jul 2012
    Posts
    11
    Rep Power
    0
    Here is the exact error

    This error (HTTP 500 Internal Server Error)
  16. #9
  17. Contributing User
    ASP Skiller (1500 - 1999 posts)

    Join Date
    Mar 2005
    Location
    Columbus, OH
    Posts
    1,607
    Rep Power
    278
    you should uncheck "show friendly HTTP error messages" checkbox in IE click tools/options advanced tab uncheck and apply. After that you should see actual error and line number and not generic message
  18. #10
  19. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jul 2012
    Posts
    11
    Rep Power
    0
    Originally Posted by gk53
    you should uncheck "show friendly HTTP error messages" checkbox in IE click tools/options advanced tab uncheck and apply. After that you should see actual error and line number and not generic message
    Ok now wer're getting somewhere - I get

    ADODB.Recordset error '800a0e7d'

    The connection cannot be used to perform this operation. It is either closed or invalid in this context.

    /query.asp, line 10
  20. #11
  21. Contributing User
    ASP Skiller (1500 - 1999 posts)

    Join Date
    Mar 2005
    Location
    Columbus, OH
    Posts
    1,607
    Rep Power
    278
    which line is #10?
    Check you connection string...
    I guess, you can not open connection
    and publish code you using
  22. #12
  23. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jul 2012
    Posts
    11
    Rep Power
    0
    Here is line 10

    cn.open "PROVIDER=SQLOLEDB;DATA SOURCE=192.168.224.79;DATABASE=Exchange;USER ID=user;PASSWORD=password;"

    Thanks again.
  24. #13
  25. Contributing User
    ASP Skiller (1500 - 1999 posts)

    Join Date
    Mar 2005
    Location
    Columbus, OH
    Posts
    1,607
    Rep Power
    278
    try that connection string

    Provider=SQLOLEDB;Data Source=192.168.224.79;Initial Catalog=Exchange;User ID=user;Password=password;

    It should be initial catalog not database
  26. #14
  27. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jul 2012
    Posts
    11
    Rep Power
    0
    Thanks I will try it.
  28. #15
  29. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jul 2012
    Posts
    11
    Rep Power
    0
    Now it says

    Microsoft VBScript compilation error '800a0401'

    Expected end of statement

    /query.asp, line 10

    Provider=SQLOLEDB;Data Source=192.168.6.79;Initial Catalog=Exchange;User ID=password;Password=password;
    -----------------^
Page 1 of 2 12 Last
  • Jump to page:

Similar Threads

  1. nees help with registration page code
    By alfidino in forum ASP Development
    Replies: 6
    Last Post: September 12th, 2005, 04:57 AM
  2. Sql to Asp Problem.
    By jheinzman in forum Programming Help
    Replies: 3
    Last Post: March 15th, 2005, 11:32 AM
  3. SQL Statement Case selection...
    By plasma800 in forum SQL Development
    Replies: 1
    Last Post: May 4th, 2004, 06:13 AM
  4. How to connect SQL Server with ASP Page
    By rrkagrawal in forum SQL Development
    Replies: 1
    Last Post: October 7th, 2003, 11:45 AM
  5. Creating a database table using SQL CREATE TABLE
    By Steve Schofield in forum SQL Development
    Replies: 1
    Last Post: June 25th, 2001, 05:39 PM

IMN logo majestic logo threadwatch logo seochat tools logo