1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

problem with database connectivity

Discussion in 'C#' started by akinak, Oct 21, 2008.

  1. #1
    I am trying to connect to MS Access 2003 database with classic ASP. Here is a sample of my asp code:
    SEMrush
    <% 
    Dim adoCon         
    Dim rs
    Dim strSQL   
    Set adoCon = Server.CreateObject("ADODB.Connection")
    adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("db1.mdb")
    Set rs = Server.CreateObject("ADODB.Recordset")    
    strSQL = "SELECT record.link, record.date FROM record;"  
    rs.Open strSQL, adoCon
    Do While not rs.EOF %>
    <table width="100%" border-"1">
     <tr><td> <% Response.Write (rs("Link")) %> </td></tr>
       <tr> <td> <% Response.Write (rs("Date")) %> </td>
        </tr>
    <%
         rs.MoveNext 
    Loop
    %>
    </table>
    <%
    rs.Close
    Set rs = Nothing
    Set adoCon = Nothing
    %>
    Code (markup):
    db1.mdb is in the root folder on my server.

    I do not see anything on the page..its blank. plz help.
     
    akinak, Oct 21, 2008 IP
    SEMrush
  2. sampathsl

    sampathsl Guest

    Messages:
    861
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Please give the IUSR user permissions to the database folder.
     
    sampathsl, Oct 21, 2008 IP
  3. akinak

    akinak Peon

    Messages:
    256
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    How to do that? Sorry I am new to this..
     
    akinak, Oct 21, 2008 IP
  4. akinak

    akinak Peon

    Messages:
    256
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    anyone..plz help
     
    akinak, Oct 22, 2008 IP
  5. Sean@WMS

    Sean@WMS Peon

    Messages:
    134
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Well, as all you are doing here is reading from the .mdb, it shouldn't be a permissions issue. Is the script in the webroot as well?

    It's a bummer that you are getting a blank page instead of an error. If you want to PM me your email address, I'll send you a custom error handling script that will detail everything you could know about ASP errors.

    Make sure there's no "On Error Resume Next" above this script, as that would give you a blank page if there were an error.

    I do see one thing that you'll want to change here, even though it wouldn't be causing a scripting error:

    
    rs.Open strSQL, adoCon
    Do While not rs.EOF %>
    <table width="100%" border-"1">
     <tr><td> <% Response.Write (rs("Link")) %> </td></tr>
       <tr> <td> <% Response.Write (rs("Date")) %> </td>
        </tr>
    <%
         rs.MoveNext 
    Loop
    %>
    </table>
    
    Code (markup):
    should be:
    
    rs.Open strSQL, adoCon %>
    <table width="100%" border="1">
    <% 
    Do While not rs.EOF %>
     <tr><td> <% Response.Write (rs("Link")) %> </td></tr>
       <tr> <td> <% Response.Write (rs("Date")) %> </td>
        </tr>
    <%
         rs.MoveNext 
    Loop
    %>
    </table>
    
    Code (markup):
    That is, start your table before the loop.

    Or maybe better yet:
    <% 
    Dim adoCon         
    Dim rs
    Dim strSQL  
    Dim strOut 
    Set adoCon = Server.CreateObject("ADODB.Connection")
    adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("db1.mdb")
    Set rs = Server.CreateObject("ADODB.Recordset")    
    strSQL = "SELECT record.link, record.date FROM record;"  
    rs.Open strSQL, adoCon
    strOut = "<table width=""100%"" border=""1"">"
    Do While not rs.EOF
     strOut = strOut & "<tr><td>" & rs("Link") & "</td></tr>" & _
     "<tr><td>" & rs("Date") & "</td></tr>"
         rs.MoveNext 
    Loop
    strOut = strOut & "</table>"
    rs.Close
    Set rs = Nothing
    Set adoCon = Nothing
    Response.Write strOut
    %>
    
    Code (markup):
     
    Sean@WMS, Oct 22, 2008 IP
  6. dinomflorist

    dinomflorist Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    check your Server.MapPath

    with this code

    response.write Server.MapPath
    you will know exactly the folder
     
    dinomflorist, Oct 28, 2008 IP
  7. Sean@WMS

    Sean@WMS Peon

    Messages:
    134
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #7
    No bad advise, but no likely the issue here either.
     
    Sean@WMS, Oct 28, 2008 IP
  8. ranabra

    ranabra Peon

    Messages:
    125
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    You say "I do not see anything on the page..its blank"

    Go and view the page source. most likely you will find an error displayed
     
    ranabra, Oct 29, 2008 IP
  9. akinak

    akinak Peon

    Messages:
    256
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    no error in source code..but i guess its because the website is hosted on linux. I am going to change it to windows.
     
    akinak, Oct 29, 2008 IP
  10. kadesmith

    kadesmith Peon

    Messages:
    479
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Just looking at your code I would suggest that you don't place the database in the wwwroot folder. You may want to create a folder called like db at the same level as the root. Then in your code do something like Server.MapPath("..\db1.mdb")

    If you place it in the wwwroot others will be able to download it. Just a thought for you to consider.
     
    kadesmith, Oct 29, 2008 IP
  11. akinak

    akinak Peon

    Messages:
    256
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    That a good point. Will definitely take care of it. thnx
     
    akinak, Oct 30, 2008 IP