Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Need a new set of eyes on asp code
Old 06-07-2007, 12:46 PM Need a new set of eyes on asp code
Average Talker

Posts: 27
Trades: 0
I am beating my head against the wall on where my error is. Can someone else please look at my code and tell me what is wrong? Thank you for the help!

<%
Dim Connection
Dim DSN
Dim Recordset
Dim SQL

DSN ="DSN=access_speakers"

SQL = "SELECT Subjects,Presentations FROM Speakers"

Set Connection = Server.CreateObject("ADODB.Connection")
Set Recordset = Server.CreateObject("ADODB.Recordset")

connection.Open DSN

Recordset.Open SQL,Connection

If Recordset.Eof Then
response.write "There are no records."
Else

Do While NOT Recordset.Eof
Response.write Recordset("Subjects")
Response.write Recordset("Presentations")
Recordset.MoveNext
Loop
End If

Recordset.Close
Set Recordset = Nothing
Connection.Close
Set Connection = Nothing
%>
jengiss is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-07-2007, 02:35 PM Re: Need a new set of eyes on asp code
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
What error are you receiving, exactly? I don't see anything in the code on the surface that would generate an error.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 06-07-2007, 02:41 PM Re: Need a new set of eyes on asp code
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
Yeah, me neither. I'd guess if you have a saved ODBC connection as a DSN, your web server doesn't have rights to it.

But I'd also change this code:

If Recordset.Eof Then
response.write "There are no records."
Else

Do While NOT Recordset.Eof
Response.write Recordset("Subjects")
Response.write Recordset("Presentations")
Recordset.MoveNext
Loop
End If

To

While NOT Recordset.Eof
Response.write Recordset("Subjects")
Response.write Recordset("Presentations")
Recordset.MoveNext
Loop

You could put an increment in there ( i = i + 1 ) and know if no records got returned. But that simplifies things a little bit and makes it easier to maintain smaller code, without breaking things. A do loop gets executed always, no matter what, and after one iteration, then it checks the looping condition. A while loop checks before the first run, so if you're already at the EOF, it won't execute the code in the loop.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 06-07-2007, 02:51 PM Re: Need a new set of eyes on asp code
Average Talker

Posts: 27
Trades: 0
The error is when it tries to return a page. It does not seem to find the database and says:"The page can not be displayed" So then I get no page showing my results.

It is a HTTP 500 Internal Server error.

I know it is something simple so thank you for the feedback and that was a nice tip on the code change.
jengiss is offline
Reply With Quote
View Public Profile
 
Old 06-07-2007, 03:17 PM Re: Need a new set of eyes on asp code
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
Here's another code change, but this one is temporary, and you want to turn it off afterwards.

response.write("Opening database<br />")
connection.Open DSN
response.write("Opening recordset<br />")
Recordset.Open SQL,Connection
response.write("Reading data<br />")

I think you get the point. Since I don't know how to run asp code in debug mode and set breakpoints, don't even know if that's possible ( go .net ! ), some trace code will let you know how far it got before dieing.

Also, my asp is super rusty, but try adding making the first line

on error resume next

or

on error goto errorHappened:

and then however you catch it, response.write the err message. You'll need to play around like I said, because I stopped using vb script years ago and don't remember exactly all the syntax. But that should get you closer to the solution.

Is it an Access or SQL database? You might try using a connection string instead of a DSN. You can put that in an include file so you don't have a lot to manage, but that clears NTFS permissions.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Last edited by Learning Newbie; 06-07-2007 at 03:17 PM.. Reason: typo
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 06-07-2007, 03:21 PM Re: Need a new set of eyes on asp code
Average Talker

Posts: 27
Trades: 0
It is connecting to an Access database.
jengiss is offline
Reply With Quote
View Public Profile
 
Old 06-07-2007, 06:15 PM Re: Need a new set of eyes on asp code
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
I thought so. Are you running winserv03? What user is IIS running under? Probably ASP_NET or ASP_WP, I don't remember off hand, and I'm at the SQL workstation right now. Anyway, the first thing to make sure is that whatever user your asp code is running under has permission to the mdb file, and to the folder it's in (because it will have to create, manage, and delete the associated ldb file).

Might not be NTFS, but that's the type of thing where your query works when you do it by hand, and fails when you do it by code.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 06-07-2007, 08:38 PM Re: Need a new set of eyes on asp code
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
It appears that you're using Internet Explorer, so the good news is that there's a way to see the exact error message.

Go to Tools-->Internet Options-->Advanced, and uncheck the box that says "Show Friendly HTTP Error Messages". Reload your page and you'll see your error message (and more importantly, the line that it's on.)

My hunch is that John's right and that it's a connection issue, although I think the if-else logic should be left in (since it will return a 0 results message in the event that there are 0 results.) Sorry John...I gotta disagree with you at least once a year!
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)

Last edited by ADAM Web Design; 06-07-2007 at 08:39 PM..
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 06-08-2007, 11:42 AM Re: Need a new set of eyes on asp code
Average Talker

Posts: 27
Trades: 0
You guys are awesome and helped out a bunch. I ended up scrapping the DSN and just did a Connection String and it works.

Thank you so much!
jengiss is offline
Reply With Quote
View Public Profile
 
Old 06-08-2007, 03:19 PM Re: Need a new set of eyes on asp code
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
Quote:
Originally Posted by ADAM Web Design View Post
My hunch is that John's right and that it's a connection issue, although I think the if-else logic should be left in (since it will return a 0 results message in the event that there are 0 results.) Sorry John...I gotta disagree with you at least once a year!
Relevant link exchange forum for three days? Lucky thing my wife wants a romantic weekend getaway!

I'll see your disagreement, and raise a point: The if/then/else logic tests the same condition as the loop code. Both of them check RecordSet.EOF, so you'd get the same answer, but also, an empty (zero row) recordset is a valid answer (Select * From Table Where 1=2) and a different thing from an error raised by a bad query. Or maybe you're saying I should have extended the code change sample to put a message after the while loop that says if the increment field (i = i + 1, and for the record do you realize how **** hard that is to type when I'm used to i++;) is zero, print a "No records found." message? In that case, you're right.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Need a new set of eyes on asp code
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.74360 seconds with 12 queries