ASP with Access Database connectivity error.

Discussion in 'C#' started by razareal, Nov 6, 2007.

  1. #1
    I need help in connecting access database with ASP page but it shows database error can anyone will help me in this meter?
    I have attached my ASP database connectivity file with database... just let me know the error or rectify it and send back to me or you can check the codes blow:

    <%Option Explicit%>
    <HTML>
    <HEAD>
    <TITLE>Testing our connection</TITLE>
    </HEAD>
    <BODY>

    <%
    Dim adOpenForwardOnly, adLockReadOnly, adCmdTable
    adOpenForwardOnly = 0
    adLockReadOnly = 1
    adCmdTable = 2
    Dim objConn, objRS
    Set objConn = Server.CreateObject("ADODB.Connection")
    Set objRS = Server.CreateObject("ADODB.Recordset")

    Dim strDatabaseType
    'Choose one of the following two lines, and comment out the other
    strDatabaseType = "Access"
    'strDatabaseType = "MSDE"
    'Now we use this selection to open the connection in the appropriate way
    If strDatabaseType = "Access" Then
    objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=db1.mdb;" & _
    "Persist Security Info=False"
    Else
    objConn.Open "Provider=SQLOLEDB;Persist Security Info=False;" & _
    "User ID=sa;Initial Catalog=Movie;" & _
    "Initial File Name=C:\MSSQL7\Data\Movie2000.mdf"
    End If

    objRS.Open "rec", objConn, adOpenForwardOnly, adLockReadOnly, adCmdTable
    'objRS.Open "
    While Not objRS.EOF
    Response.Write objRS("ID") & "<BR>"
    objRS.MoveNext
    Wend

    objRS.Close
    objConn.Close
    Set objRS = Nothing
    Set objConn = Nothing
    %>

    </BODY>
    </HTML>


    :confused::confused::confused::confused:
    your earlier reply will be highly appreciated.
     

    Attached Files:

    • pro1.zip
      File size:
      10.2 KB
      Views:
      100
    razareal, Nov 6, 2007 IP
  2. tarponkeith

    tarponkeith Well-Known Member

    Messages:
    4,758
    Likes Received:
    279
    Best Answers:
    0
    Trophy Points:
    180
    #2
    This is how I always did it...

    
    dim dbaseconn, sqlquery, rs
    
    Set dbaseConn = Server.CreateObject("ADODB.Connection")
    dbaseConn.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.Mappath("../db/databasename.mdb") & ";"
    
    SQLQuery = "SELECT * FROM Data WHERE (ID = " & inID & ");"
    
    Set RS = dbaseConn.Execute(SQLQuery)
    
    if rs.eof then
    	Response.Redirect("http://www.no_entries.com")
    	Response.End
    else
      ' something here
    
    end if
    
    rs.close
    set rs = nothing
    
    dbaseConn.Close
    Set dbaseConn = Nothing
    Code (markup):
     
    tarponkeith, Nov 6, 2007 IP
  3. e-webtemplates

    e-webtemplates Peon

    Messages:
    355
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    what is the error you are getting ? can you post the error message ?
     
    e-webtemplates, Nov 7, 2007 IP
  4. teraeon

    teraeon Peon

    Messages:
    40
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Make sure that you put in the full path to the database, that causes a lot of errors with access. Visit http://www.connectionstrings.com and find the connection string you're going to use and make sure that's correct.
     
    teraeon, Nov 8, 2007 IP
  5. urstop

    urstop Peon

    Messages:
    224
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Try to do a repsonse.write and see the path the mappath is returning for the relative path you passed. Verify and make sure that the path returned is correct.
     
    urstop, Nov 13, 2007 IP
  6. rena

    rena Peon

    Messages:
    1,987
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #6
    dbaseconn="Provider=Microsoft.Jet.OLEDB.4.0;User ID=;Password=;Data Source=" & server.mappath("/db1.mdb")

    db1.mdb should be in root
     
    rena, Nov 17, 2007 IP