Notices

Great community. Great ideas.

Welcome to ASP/Free, a community dedicated to helping beginners and professionals alike in improving their knowledge of Microsoft's development and administration technologies. Sign up today to gain access to the combined insight of tens of thousands of members.

Thread: Connect ASP page to SQL Table

Page 1 of 2 12 LastLast
Results 1 to 15 of 21
Share This Thread →
  1. #1
    giasone777 is offline Registered User
    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
    gk53's Avatar
    gk53 is offline Contributing User
    Join Date
    Mar 2005
    Location
    Columbus, OH
    Posts
    1,538
    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

  3. #3
    giasone777 is offline Registered User
    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.

  4. #4
    gk53's Avatar
    gk53 is offline Contributing User
    Join Date
    Mar 2005
    Location
    Columbus, OH
    Posts
    1,538
    Rep Power
    278
    Why you need to call from html? Save as test.asp and call
    http://yourDomainName/test.asp

  5. #5
    giasone777 is offline Registered User
    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.

  6. #6
    gk53's Avatar
    gk53 is offline Contributing User
    Join Date
    Mar 2005
    Location
    Columbus, OH
    Posts
    1,538
    Rep Power
    278
    check you iis settings by default is it not processes asp pages only html is enabled by default

  7. #7
    giasone777 is offline Registered User
    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.

  8. #8
    giasone777 is offline Registered User
    Join Date
    Jul 2012
    Posts
    11
    Rep Power
    0
    Here is the exact error

    This error (HTTP 500 Internal Server Error)

  9. #9
    gk53's Avatar
    gk53 is offline Contributing User
    Join Date
    Mar 2005
    Location
    Columbus, OH
    Posts
    1,538
    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

  10. #10
    giasone777 is offline Registered User
    Join Date
    Jul 2012
    Posts
    11
    Rep Power
    0
    Quote 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

  11. #11
    gk53's Avatar
    gk53 is offline Contributing User
    Join Date
    Mar 2005
    Location
    Columbus, OH
    Posts
    1,538
    Rep Power
    278
    which line is #10?
    Check you connection string...
    I guess, you can not open connection
    and publish code you using

  12. #12
    giasone777 is offline Registered User
    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.

  13. #13
    gk53's Avatar
    gk53 is offline Contributing User
    Join Date
    Mar 2005
    Location
    Columbus, OH
    Posts
    1,538
    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

  14. #14
    giasone777 is offline Registered User
    Join Date
    Jul 2012
    Posts
    11
    Rep Power
    0
    Thanks I will try it.

  15. #15
    giasone777 is offline Registered User
    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 LastLast
Share This Thread →

Become Part of This Conversation

Join NowFor Free!

Similar Threads

  1. nees help with registration page code
    By alfidino in forum ASP Development
    Replies: 6
    Last Post: September 12th, 2005, 03:57 AM
  2. Sql to Asp Problem.
    By jheinzman in forum Programming Help
    Replies: 3
    Last Post: March 15th, 2005, 10:32 AM
  3. SQL Statement Case selection...
    By plasma800 in forum SQL Development
    Replies: 1
    Last Post: May 4th, 2004, 05:13 AM
  4. How to connect SQL Server with ASP Page
    By rrkagrawal in forum SQL Development
    Replies: 1
    Last Post: October 7th, 2003, 10: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, 04:39 PM

ASP Free Advertisers and Affiliates