Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 29th, 2007, 08:45 PM
Registered User
 
Join Date: Jan 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default At Minds End - SUM()

Hi All - thanks for any help you can give me with this. I'm at my minds end at this point. I'm doing the following in an ASP page:

**********************
Dim recTmp
Set db = Server.CreateObject ("ADODB.Connection")
db.Open ("DSN=MYDB")
Set recTmp = Server.CreateObject ("ADODB.Recordset")
recTmp.Open "SELECT username, SUM(distance) as TotalDistance FROM routes GROUP BY username ORDER BY TotalDistance ASC limit 0,5", db
if recTmp.EOF and recTmp.BOF then
  Response.Write "Got Nothing"
else
  Response.Write "got some"
End If

*********************

I don't receive an error, but, no matter what, I get no records returned!!!! When I paste the SQL and run it directly in my DB I get four records returned:

username TotalDistance
bill 1454
ed 1896
phil 11642
joe 35151

I'm using MYSQL as the backend db. Any ideas? And thanks again!


 
Old January 30th, 2007, 02:42 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

I may be way off but I don't think your recordset can be both at the end and at the beginning at the same time. So, it won't write anything to the page.

If recTemp.EOF Then
Response.Write("Got Nothing")
Else
Response.Write("Got Some")
End If

 
Old January 31st, 2007, 10:12 AM
Authorized User
 
Join Date: Jan 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm new, but it seems like you should set "recTmp.Open" = to the database properties/ username / password. And then run your SELECT against recTmp.Execute <SQL Code>.

As an alternative connection approach, the code I found that works for me on a SQL Server 2000 database is:
set conn=server.createobject("adodb.connection")
set rs=server.CreateObject("adodb.recordset")
conn.open = "Driver={SQL Server}; server=<Server_Name>; database=<database_name>; uid=<User_Name>; password=<password>;"
sqlrs="EXEC <Database_Name>.<Owner>.<Stored_Procedure> @param1 = '" _
& param & "'"
rs.open sqlrs, conn, 2, 2

And then I reference my SQL result set like rs("Column_Name").

Please note the underscore in the sample above is just because the code spanned multiple lines.

Hope you get some help from this post. Good Luck!

 
Old January 31st, 2007, 02:07 PM
Registered User
 
Join Date: Jan 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi danastasio and rstelma -

Thanks for the replies.

The rectmp.EOF and recTmp.BOF check is to see if I got any record sets, if no recordsets are returned than they are both true.

Danastsio -

I'm using a DSN connection so all of the passwords, and such are in the DSN record. I'll have to try writing the connection out to see if something changes.

If I try simpler queries evertyhing works fine, it is just this one query (in particular when I use SUM())


 
Old January 31st, 2007, 02:25 PM
Authorized User
 
Join Date: Jan 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks. I did not know what about DSN connections, but thanks to your post have learned a bit more today.
Have you tried response.write recTmp("Username") to verify no records are being returned?
Having a query work in the database and other queries without the SUM work in the ASP code would certainly drive me nuts. Good Luck!

 
Old January 31st, 2007, 04:16 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

It seems like if your connection wasn't working you'd be getting some kind of error.
What is your database?

Try this.

Dim recTmp
Set db = Server.CreatObject("ADODB.Connection")
db.Open(""DSN=MYDB;")
SQL = "SELECT username, SUM(distance) as TotalDistance FROM routes GROUP BY username ORDER BY TotalDistance ASC limit 0,5;"
Set recTmp = db.Execute(SQL)

If not recTmp.EOF Then
Do While not recTmp.EOF
Response.Write username & " " & TotalDistance & "<br>"
recTmp.MoveNext
Loop
Else
Response.Write "No Records Found."
End If

recTmp.Close
Set recTmp = Nothing
db.Close
Set db = Nothing



 
Old January 31st, 2007, 04:59 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Are you sure you're not getting an error? Take a look at the resulting HTML in the browser.

Quite often in ASP sites, the error does occur but is not displayed on the page because it's written inside some <table> tags in the markup. By looking at the final HTML, you may see an error that otherwise isn't visible in the page.

HtH,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old January 31st, 2007, 06:52 PM
Registered User
 
Join Date: Jan 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi all - thanks again for the replies. Unfortunately, no luck. The database is MYSQL 5+

 - Yep, I've checked the source of the page but no errors.
 - If I print out a value before the If statement that checks for recordsets I get an error (mostly out of index errors verifying no record sets). I've tried:

Response.Write recTmp("username)
Response.Write recTmp.Fields.Item("username")
Response.Write recTmp.Fields("username")
Response.Write recTmpFields.Item(0)
Response.Write recTmp.Items("username")

All giving out of index errors or this:

Microsoft OLE DB Provider for ODBC Drivers error '80020009'

[Microsoft][ODBC Driver Manager] Program type out of range

/include/test.asp, line 0

 
Old January 31st, 2007, 10:00 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

Maybe this will help. Have you seen it?

http://support.microsoft.com/kb/175239






Similar Threads
Thread Thread Starter Forum Replies Last Post
Front end Vs Back end ricmar Access VBA 3 May 27th, 2008 02:36 PM
Ms Access front End with Oracle 10g Back End rahul123 Oracle 1 July 9th, 2007 01:03 AM
Oracle back-end MS-Access 2003 client front-end Corey Access 2 February 16th, 2007 08:31 AM
Oracle Back End - MS Access Front End - Multi User ckaliveas Oracle 1 February 1st, 2007 06:00 AM
Help: Running Sum (or Cumulative Sum) timdasa VB Databases Basics 1 August 22nd, 2006 03:12 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.