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> your earlier reply will be highly appreciated.
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):
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.
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.
dbaseconn="Provider=Microsoft.Jet.OLEDB.4.0;User ID=;Password=;Data Source=" & server.mappath("/db1.mdb") db1.mdb should be in root