Old 11-04-2006, 09:24   #1 (permalink)
silver
Registered User
 
Join Date: Apr 2006
Posts: 2
Connection to Access database

hi, iam trying to connect to the access database using DSN but with no luck, can you please help me. iam new to web design! i was using an example to help me but it is not working, look at the program and give me some suggestions. thanks.

<% @LANGUAGE = VBScript %>
<% Option Explicit %>

<% ' Fig. 25.24 : login.asp %>

<% Dim connection, query, loginData

Set connection = Server.CreateObject( "ADODB.Connection" )
Call connection.Open( "login" )

' Create the SQL query
query = "SELECT loginID FROM Users"

' Create the recordset
Set loginData = Server.CreateObject( "ADODB.Recordset" )
Call loginData.Open( query, connection )

' If an error occurs, ignore it
On Error Resume Next
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD><TITLE>Login Page</TITLE></HEAD>

<BODY>

<!-- #include virtual="/includes/mgtheader.shtml" -->

<%
' If this is a return after a failed attempt,
' print an error
If Session( "loginFailure" ) = True Then %>
<FONT SIZE = "4" COLOR = "red"> Login attempt failed,
please try again <P></FONT>
<% End If

' Begin the form %>
<FONT FACE = "Arial" SIZE = "2">
Please select your name and enter
your password to login:<BR>
</FONT>
<FORM ACTION = "submitlogin.asp" METHOD = "POST">

<% ' Format the form using a table %>
<TABLE BORDER = "0">
<TR>
<TD><FONT FACE = "Arial" SIZE = "2">Name:</FONT></TD>
<TD><SELECT NAME = "loginID">
<OPTION VALUE = "noSelection">Select your name

<% ' If the loginID cookie is an empty string then there is
' no need to consider the returning case
If Request.Cookies( "loginID" ) <> "" Then
Call BuildReturning()
Else
Call BuildNewUser()
End If
%>

</SELECT>
</TD>
</TR>

<TR>
<TD><FONT FACE = "Arial" SIZE = "2">Password:</FONT></TD>
<TD><INPUT TYPE = "password" NAME = "password"></TD>
</TR>
<TR>
<TD>&nbsp;</TD>
<TD ALIGN = "left">
<INPUT TYPE = "submit" VALUE = "Log Me In">
</TD>
</TR>
</TABLE>
</FORM>
</FONT>

<!-- #include virtual="/includes/mgtfooter.shtml" -->

</BODY>
</HTML>

<% ' Builds the OPTION items for loginIDs and writes
' selected for the loginID of the returning user
Sub BuildReturning()
Dim found

' Pull user names from the record set to populate the
' dropdown list
found = False
While Not loginData.EOF
' Create this record's dropdown entry
%> <OPTION
<% ' If we did not write SELECTED for any OPTION
' before
If ( Not found ) Then

' If the current record's loginID is equal to
' the loginID cookie, then it is the loginID of
' the returning user, and thus we need to write
' SELECTED for this option; in this case we also
' need to signal that we have written SELECTED
' for an OPTION by setting found to True.
If Request.Cookies( "loginID" ) _
= loginData( "loginID" ) _
Then
Call Response.Write( "SELECTED" )
found = True
End If
End If
%> VALUE = "<% =loginData( "loginID" ) %>">
<% =loginData( "loginID" ) %>
<% Call loginData.MoveNext()
Wend
End Sub

' Builds the OPTION items for loginIDs without writing
' SELECTED for any loginID
Sub BuildNewUser()

' Pull user names from the record set to populate the
' dropdown list
While Not loginData.EOF
' Create this record's dropdown entry
%>
<OPTION VALUE = '<% =loginData( "loginID" ) %>'>
</OPTION>
<% =loginData( "loginID" ) %>
<% Call loginData.MoveNext()
Wend
End Sub
%>
  Reply With Quote
Old 11-04-2006, 09:44   #2 (permalink)
forwardtrends
forwardtrends.com
 
Join Date: Mar 2006
Location: Pittsburgh, PA
Posts: 67
Instead of using a DSN, try mapping straight to the DB:

strconn = "Driver={Microsoft Access Driver (*.mdb)};User ID=xxx Password=xxx; DBQ=c:/inetpub/yoursite/access_db/yourdb.mdb"
set objconn=server.createobject("adodb.connection")
objconn.connectionstring = strconn
objconn.open

To figure out where your db is located on the server use this code in the same directoy or the root directory and figure it out:

<%=Server.MapPath("You are here")%>

Opening your recordset would be as simple as:

strsql="SELECT * FROM yourtable"

Set objrs=objconn.execute(strsql)
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8