MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 17th, 2002, 08:40 PM
jerzeh jerzeh is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 5 jerzeh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
mysql via asp

Hi all,

I am having a problem with mysql via asp that I was hoping you could help me with. I have my database set up through asp so i can perform inserts and queries--I know it's not a severe connection problem. But when i evaluate the RecordCount property it yields -1 and .EOF and .BOF always yield FALSE. I tried using a DSN with the "Return matching rows" box checked and without a dsn using 'Option=0' in the connection string. Neither of these seem to work. I am getting results from the selects (the fields have values), I just dont know how many records im getting back. Anyone have any ideas? Thanks in advance for any help you could give.

Regards,
Jeremy

Reply With Quote
  #2  
Old July 18th, 2002, 08:35 PM
mytch mytch is offline
Dev Articles Novice (500 - 999 posts)
 
Join Date: Apr 2002
Location: Sydney, Australia
Posts: 589 mytch User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
That's a common problem with ASP. You need to set the lockType and cursorLocation properties of your recordset. Here's a quick example:

<%
' change these for your site
connectme="DSN=Student;uid=student;pwd=magic"
sqltemp="select * from publishers where state='NY'"
set rstemp=Server.CreateObject("adodb.Recordset")
rstemp.open sqltemp, connectme, adopenstatic
howmanyrecs=rstemp.recordcount
response.write howmanyrecs & " records in<br>" & sqltemp
rstemp.close
set rstemp=nothing
%>

Reply With Quote
  #3  
Old December 3rd, 2002, 12:58 AM
wolfpac3d wolfpac3d is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: Florida
Posts: 6 wolfpac3d User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I have tried the same thing. Is there something we are missing maybe in mysql when setting up the connection through the drivers instead of code?

Reply With Quote
  #4  
Old December 3rd, 2002, 04:00 AM
darkvalley darkvalley is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: Netherland
Posts: 15 darkvalley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Sometimes an recordset will return one empty row and thus no information is available at that time. A possible solution to this is the use of the GetRows statement and fill a dynamic array. Then simply count the number of rows that are in the dynamic array.

A short example.

<%
database connection
connection.open
SQL statement.

recordset.Open
IF NOT recordset.Eof THEN
dynamic_array = recordset.Getrows
dynamic_array_rows = Ubound(dynamic_array, 2)
ELSE
dynamic_array_rows = -1
END IF
recordset.Close
connection.Close

SET recordset = Nothing
SET connection = Nothing


IF dynamic_array_rows >= 0 THEN
Count = 0
DO WHILE dynamic_array_rows <= Count
response.write(dynamic_array(0,Count))
Count = Count + 1
Loop
ELSE
response.write("No records Found")
END IF

%>


The example will simply fill the dynamic array with all the records found and then count the number of rows. (that is the ubound,2 statement) then close all connections and use the dynamic array to display the information.

WARNING: the first row starts at 0 thus if the eof statement is true then the rows should start at -1

NOTE: this example is vb / asp.

Hope it will help,

Werner.

Reply With Quote
  #5  
Old December 3rd, 2002, 05:14 PM
Kanu Kanu is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 91 Kanu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Man, ASP seems 50 times more complex than PHP, it's just so unnecessary.

Reply With Quote
  #6  
Old December 4th, 2002, 09:45 PM
peeyush peeyush is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: India
Posts: 17 peeyush User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to peeyush
Hi all

Its not difficult to create a connection of ASP with MySQL

Remember all the constants like adOpenDynamic, etc. and all the lock type Optimistic etc. constants will not work if you dont include a file called as 'adovbs.inc' in your asp page.

adovbs.inc is located in <Drive Name>\Program Files\Common Files\System\ADO\

To get the RecordCount property right remember to open recordset with CursorType = adOpenStatic

Here is a sample code to make a connection with MySQL

<%
On Error Resume Next

Dim cn
Dim rs

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

'connection using System DSN make sure MyODBC is installed on the system with web server

cn.ConnectionString = "DSN=mysql_dsn_name;uid=username;pwd=password"


'Now remember to execute Insert, Update, Delete query you dont have to make a recordset
'just type this text -- cn.Execute "SQL query" -- and then cn.Close
'for Select queries use this

rs.ActiveConnection = cn
rs.CursorType = 2 'equivalent to Dynamic recordset
rs.LockType = 2 'equivalent to Optimistic lock

rs.Open "Select * from table_name"

'after this use can use rs recordset for different purposes
'and finally

rs.Close
cn.Close

Set rs = Nothing
Set cn = Nothing
%>

Hope this helps.

Reply With Quote
  #7  
Old December 6th, 2002, 12:22 PM
wolfpac3d wolfpac3d is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: Florida
Posts: 6 wolfpac3d User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
mysql

if it isn't so hard then why do I still get a -1 when i use the following script


set buyerconn = Server.CreateObject("adodb.connection")
buyerconn.mode = 3
buyerconn.connectionstring = "dsn=cddata"
buyerconn.open

Set buyeror = Server.CreateObject("ADODB.Recordset")
buyeror.open "Select * from Buyer_property where agent_number = '" & session("username") & "'",buyerconn,2,2


My query is correct. I did the gentlemen in one of these post idea and it works. The only thing I am having a real problem with is my VB code. It errors on me when I try to use this code.

Reply With Quote
  #8  
Old December 7th, 2002, 07:06 AM
darkvalley darkvalley is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: Netherland
Posts: 15 darkvalley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I think you missed the closing quote for the sql statement..

Perhaps fill a variable with the sql query first and then use the open statement..

for example.

var_sql = "Select * "
var_sql = var_sql & "from table "
var_sql = var_sql & "where customer_id = ' " & session("cust_id") & " ';"

Then open the var_sql statement



As for the -1.. this indicates that there are 0 lines returned. which explanes the bof or eof statement..

Reply With Quote
  #9  
Old December 7th, 2002, 11:53 AM
wolfpac3d wolfpac3d is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: Florida
Posts: 6 wolfpac3d User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Then answer me this why does this code work:

set oConn = Server.CreateObject("adodb.connection")
oconn.mode = 3
oconn.connectionstring = "dsn=cddata"
oconn.open

set ors = server.createobject("adodb.recordset")
ors.open "Select * from Agents where code = '" & session("username") & "'",oconn,2,2

Reply With Quote
  #10  
Old December 7th, 2002, 12:11 PM
darkvalley darkvalley is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: Netherland
Posts: 15 darkvalley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
What error message do you get.

Perhaps it is related to the variable you use.. If this session variable is empty you'll get a strange error message like not acceptible sql query bla bla..

Reply With Quote
  #11  
Old December 8th, 2002, 11:09 PM
apjohnsto apjohnsto is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2002
Posts: 3 apjohnsto User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
movelast...

try doing a movelast and movefirst, and then evaluate the recordcount. e.g.

rs.movelast
rs.movefirst
i = rs.recordcount

this should be a fool-proof way of getting the recordcount. i know in earlier versions of ado/dao, the recordcount would not be set correctly unless you did this. if you still get -1 after doing this, then you are either not getting any results or there must be some problem with the mysql odbc driver you are using...

what versions of the following are you using:
ADO
ASP/IIS
MySQL
MySQL ODBC Driver

??

Reply With Quote
  #12  
Old December 13th, 2002, 03:57 PM
crazytrain81 crazytrain81 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 232 crazytrain81 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
A note about ADO in ASP / VBScript...

To use the various ad... constants, such as adLockOptimistic, adChar, adCmdProc, adCmdTable, and adOpenKeyset, without having to use the numerical values, you need to include the adovbs.inc file. Just search your C drive for it and put it in your includes folder. It saves you the trouble of learning (or more than likely, looking up) the constants and their actual values =)

Reply With Quote
  #13  
Old November 26th, 2003, 09:03 AM
Manbos Manbos is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 1 Manbos User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Recordcount work ok with code:

Set rs = Server.CreateObject("ADODB.RecordSet")

'--------------------------------------
rs.CursorLocation=adUseClient
rs.CursorType=adOpenStatic
rs.LockType=adLockBatchOptimistic
'--------------------------------------

rs.Open strSQL, conn


This one method for work fine.
The CursorLocation = adUseClient is the key.

Greetings,

Manbos
URL

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > mysql via asp


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by