Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP to MS Access Connection 2

Status
Not open for further replies.

haneen97

Programmer
Dec 10, 2002
280
US
Hi Team,
I have this simple page to display the contents of a table in a database on the local machine as you can tell. All I get is the header line. I don't get any error or anything. Just a blank page. The table has data. Please help



<%
<%@ LANGUAGE = VBScript %>
<% Option Explicit %>
<%
'*****************************************************
'* Code written by XXXXXXX *
'*****************************************************
%>

<HTML>
<BODY BGCOLOR="White" topmargin="10" leftmargin="10">
<B>Here are the specialties:<B><BR>
<%
dim MyConn
dim RS
dim DbPath

DbPath = Server.MapPath("C:\aRxSoft\DB\RxSoft.mdb")
Set MyConn = Server.CreateObject("ADODB.Connection")
MyConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DbPath
Set RS = Server.CreateObject("ADODB.Recordset")
Set RS = MyConn.Execute("SELECT * FROM Specialty")
'Loop through the recordset
Do While not RS.EOF

'Write the HTML to display the current record in the recordset
Response.Write ("<br>")
Response.Write (RS("Specialty_Id"))
Response.Write ("<br>")
Response.Write (RS("Specialty"))
Response.Write ("<br>")
Response.Write (RS("Degree"))
Response.Write ("<br>")

'Move to the next record in the recordset
RS.MoveNext

Loop

RS.Close
set RS = Nothing
set MyConn = Nothing
%>
</BODY>
</HTML>


Thanks

Mo
 
If you use "View Source" to see the HTML created by this ASP do you see all of the <br> tags that are on each row?

Or is it not going into the loop because RS.EOF is true?
 
This is what I see when I view source. I think you are right. It is hitting the EOF. Is that mean that the RS is empty?

<MM:BeginLock translatorClass="MM_ASPSCRIPT" type="script" depFiles="" orig="%3C%25
%3C%25@ LANGUAGE = VBScript %25%3E" ><MM_ASPSCRIPT><MM:EndLock>
<MM:BeginLock translatorClass="MM_ASPSCRIPT" type="script" depFiles="" orig="%3C%25 Option Explicit %25%3E" ><MM_ASPSCRIPT><MM:EndLock>
<MM:BeginLock translatorClass="MM_ASPSCRIPT" type="script" depFiles="" orig="%3C%25
'*****************************************************
'* Code written by XXXXXXX *
'*****************************************************
%25%3E" ><MM_ASPSCRIPT><MM:EndLock>

<HTML>
<BODY BGCOLOR="White" topmargin="10" leftmargin="10">
<B>Here are the specialties:<B><BR>
<MM:BeginLock translatorClass="MM_ASPSCRIPT" type="DynamicSource" depFiles="" orig="%3C%25
dim MyConn
dim RS
dim DbPath

DbPath = Server.MapPath(%22C:\aRxSoft\DB\RxSoft.mdb%22)
Set MyConn = Server.CreateObject(%22ADODB.Connection%22)
MyConn.Open %22Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%22 & DbPath
Set RS = Server.CreateObject(%22ADODB.Recordset%22)
Set RS = MyConn.Execute(%22SELECT * FROM Specialty%22)
'Loop through the recordset
Do While not RS.EOF

'Write the HTML to display the current record in the recordset
Response.Write (%22%3Cbr%3E%22)
Response.Write (RS(%22Specialty_Id%22))
Response.Write (%22%3Cbr%3E%22)
Response.Write (RS(%22Specialty%22))
Response.Write (%22%3Cbr%3E%22)
Response.Write (RS(%22Degree%22))
Response.Write (%22%3Cbr%3E%22)

'Move to the next record in the recordset
RS.MoveNext

Loop

RS.Close
set RS = Nothing
set MyConn = Nothing
%25%3E" ><MM_RECORDSET NAME="RS" DYNAMICSOURCE=1></MM_RECORDSET><MM:EndLock>
</BODY>
</HTML>

Mo
 
a couple of things, i don't belive you can do this
Code:
DbPath = Server.MapPath("C:\aRxSoft\DB\RxSoft.mdb")

it has to be this
Code:
DbPath = Server.MapPath("DB/RxSoft.mdb")
or this
Code:
DbPath = "C:\aRxSoft\DB\RxSoft.mdb"

but excuse me if i'm wrong, i have the flu


second thing is you don't need this line
Code:
Set RS = Server.CreateObject("ADODB.Recordset")
because you are doing this
Code:
Set RS = MyConn.Execute("SELECT * FROM Specialty")
 
You can test to see if you are getting EOF
Code:
If RS.EOF Then
     Response.Write "We've hit bottom"
Else
Do While not RS.EOF
    
     'Write the HTML to display the current record in the recordset
     Response.Write (%22%3Cbr%3E%22)
     Response.Write (RS(%22Specialty_Id%22))
     Response.Write (%22%3Cbr%3E%22)
     Response.Write (RS(%22Specialty%22))
     Response.Write (%22%3Cbr%3E%22)
     Response.Write (RS(%22Degree%22))
     Response.Write (%22%3Cbr%3E%22)
     
     'Move to the next record in the recordset
     RS.MoveNext

 Loop  

End If

That will at least give you some idea what's going on.

Paul
 
Well, just looking at your source, I say you are missing a script delimmitter because your server side code is showing up in your HTML source.

Try putting <% and %> around the start and end of your code.
 
It looks like your code has the proper delimmitters, but they why is it showing up this way?


What do you see in the browser address bar? Maybe you have just clicked on the .asp file the same way you click on an .htm file? That won't work. In order for the server to process the ASP then the file must be requested from the server with a type of address instead of a C:\blah\blah\desktop\whatever.asp address.
 
Hi,
Thanks for your help and I wish you feel better.

I made those changes but still get the same results. Only the header line.

Thanks

Mo
 
haneen,

your code is fine except for minor things

1. typo w/ first line <% cannot be before <@ LANGUAGE=VBScript%>

2. since you have 2 directories to get to your database...stevens second path code is correct so change that

see your code in action here: note: i put in bogus info in database w/ your fields


i named it speciality.asp

Code:
<%@ LANGUAGE = VBScript %>
<%  Option Explicit        %>
<%
'*****************************************************
'* Code written by XXXXXXX                             *
'*****************************************************
%>

<HTML>
<BODY BGCOLOR="White" topmargin="10" leftmargin="10">
<B>Here are the specialties:<B><BR>
<%
 dim MyConn
 dim RS
 dim DbPath
 
 Set MyConn = Server.CreateObject("ADODB.Connection")
 Set RS = Server.CreateObject("ADODB.Recordset")
 DbPath = Server.MapPath("aRxSoft\DB\RxSoft.mdb")
 MyConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DbPath
 Set RS = Server.CreateObject("ADODB.Recordset")
 Set RS = MyConn.Execute("SELECT * FROM Specialty")
'Loop through the recordset
 Do While not RS.EOF
    
     'Write the HTML to display the current record in the recordset
     Response.Write ("<br>")
     Response.Write (RS("Specialty_Id"))
     Response.Write ("<br>")
     Response.Write (RS("Specialty"))
     Response.Write ("<br>")
     Response.Write (RS("Degree"))
     Response.Write ("<br>")
     
     'Move to the next record in the recordset
     RS.MoveNext

 Loop        

 RS.Close
 set RS = Nothing
 set MyConn = Nothing
%>
</BODY>
</HTML>
 
It doesn't matter what your code is as long as you can see it when you do "View Source" because that means the code is not being processed by the web server. You're code could be 100% correct and it won't work if it isn't processed.
 
to find out if RS.EOF you should check for that so you do not get an error...print a "friendly" message to user

ie:
Code:
<%
If RS.EOF Then
  Response.Write "No Records Found"

Else

Do While not RS.EOF
    
     'Write the HTML to display the current record in the recordset
     Response.Write ("<br>")
     Response.Write (RS("Specialty_Id"))
     Response.Write ("<br>")
     Response.Write (RS("Specialty"))
     Response.Write ("<br>")
     Response.Write (RS("Degree"))
     Response.Write ("<br>")
     
     'Move to the next record in the recordset
     RS.MoveNext

 Loop        
End If
%>
 
Dude, look at the "view source" that was posted above.

The code is not running. It is showing up as HTML.

gotta fix that before the code can be fixed.
 
bslintx's idea worked. I think I am missing something in the set up. I have to review my ste up I guess. Let me digest this a little first.

Mo
 
oh yeah...try to write 1 response when possible...easier to read and (less hits on server)

change

Code:
'Write the HTML to display the current record in the recordset
     Response.Write ("<br>")
     Response.Write (RS("Specialty_Id"))
     Response.Write ("<br>")
     Response.Write (RS("Specialty"))
     Response.Write ("<br>")
     Response.Write (RS("Degree"))
     Response.Write ("<br>")

to
Code:
'Write the HTML to display the current record in the recordset
    
 Response.Write "<p>" & RS("Specialty_Id") & "<br>" & vbCrlf & _
               "RS("Specialty") & "<br>" & vbCrlf & _
               "RS("Degree") & "</p>"
 
steven is also right ...even though i have it verbatim on the example you see and it works you should take out the duplicate Set RS = Server.CreateObject("ADODB.Recordset")
as steven so happen to mention...sorry steven...missed your comment;-)

Brian
 
I test the page by "preview in the browser" option. I think I am missing something in the set up. Also, I am using a persona server IIS set up. I have to digest this a little I guess.

Mo
 
do you have an equivilent to ms iis inetpub directory? i'm not familiar w/ persona

BSL
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top