Solved

asp query in mysql

Posted on 2004-05-01
14
676 Views
Last Modified: 2006-11-17

how do i run a query on a mysql server in asp?  i want a dsn-less connection

thanks
0
Comment
Question by:CookieMonster9999
  • 7
  • 5
  • 2
14 Comments
 
LVL 33

Accepted Solution

by:
hongjun earned 200 total points
ID: 10969723
0
 
LVL 33

Expert Comment

by:hongjun
ID: 10969729
How do you run?

SELECT Query
=========
Set rs = Conn.Execute("SELECT * from yourtable")

Update / insert/ delete
===============
Conn.Execute "Your update / insert / delete query here"


hongjun
0
 

Author Comment

by:CookieMonster9999
ID: 10969821


Here's what I have from the site:

oConn.Open "Driver={mySQL};" & _
           "Server=db1.database.com;" & _
           "Port=3306;" & _
           "Option=131072;" & _
           "Stmt=;" & _
           "Database=mydb;" & _
           "Uid=myUsername;" & _
           "Pwd=myPassword"

I filled in all my info and get object required
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
LVL 6

Expert Comment

by:Lord_McFly
ID: 10969947
You need to create a connection object first before opening it - as follows...

Set oConn = Server.CreateObject("ADODB.Connection")
0
 

Author Comment

by:CookieMonster9999
ID: 10969955
thanks
0
 

Author Comment

by:CookieMonster9999
ID: 10969963
i am still having a problem trying to count the number of records in the recordset with this code.  I have


Set oConn = Server.CreateObject("ADODB.Connection")
stroConn = "Driver={mySQL};" & _
           "Server=db1.database.com;" & _
           "Port=3306;" & _
           "Option=131072;" & _
           "Stmt=;" & _
           "Database=mydb;" & _
           "Uid=myUsername;" & _
           "Pwd=myPassword"
oConn.Open stroConn

When i do the following
sqltemp30 = " SELECT * FROM tblImaginary"
Set rstemp30=Server.CreateObject("adodb.RecordSet")
rstemp30.open sqltemp30, stroConn, adopenstatic
howmanyrecs30=rstemp30.recordcount

it always results in -1 no matter how many recs there are in the query

(i've adjusted points to 500 to accomodate answering this additional part)
0
 
LVL 6

Expert Comment

by:Lord_McFly
ID: 10969966
Hi, I noticed that you haven't put a value for the 'Server' parameter - this can be your local IP, 192.0.0.1 (for example).
0
 

Author Comment

by:CookieMonster9999
ID: 10969977
i have the queries working, just wondering how to do make record count work.

i've just switched from access to mysql and i'm having to fix all my damn queries :(
0
 
LVL 6

Expert Comment

by:Lord_McFly
ID: 10969989
You are using an ADO constant 'adoopenstatis' - in order to utilise that you would need to include the following...

<!-- #include file="adovbs.inc" -->

...which is provided by Microsoft (it enumerates the ADO constants).

Alternatively you can just put the following...

rstemp30.open sqltemp30, stroConn, 3

3 = adOpenKeyset, which is required to return a record count.

0
 
LVL 6

Expert Comment

by:Lord_McFly
ID: 10969999
Apologies :)

3 is adOpenStatic
0
 

Author Comment

by:CookieMonster9999
ID: 10970003
I actually have the file included already.

I tried switching it to 3 and it resulted in:

Microsoft OLE DB Provider for ODBC Drivers error '80040e21'
ODBC driver does not support the requested properties.
 
 
0
 

Author Comment

by:CookieMonster9999
ID: 10970012
Nevermind, it still results in -1.  Here is the query:

sqltemp30 = " SELECT tblGenreMatch.GenreID, tblMusic.SongReviewStatus FROM tblMusic INNER JOIN tblGenreMatch ON tblMusic.SongID = tblGenreMatch.SongID WHERE tblGenreMatch.GenreID= " & genreid & " AND tblMusic.SongReviewStatus='Accepted';"


Set rstemp30=Server.CreateObject("adodb.RecordSet")
rstemp30.open sqltemp30, strMyConn, 3
howmanyrecs30=rstemp30.recordcount
0
 
LVL 6

Assisted Solution

by:Lord_McFly
Lord_McFly earned 300 total points
ID: 10970016
The following is a snippet from the mySQL website on the subject of using RecordCount...

ADO

When you are coding with the ADO API and MyODBC you need to put attention in some default properties that aren't supported by the MySQL server. For example, using the CursorLocation Property as adUseServer will return for the RecordCount Property a result of -1. To have the right value, you need to set this property to adUseClient, like is showing in the VB code here:
Dim myconn As New ADODB.Connection
Dim myrs As New Recordset
Dim mySQL As String
Dim myrows As Long

myconn.Open "DSN=MyODBCsample"
mySQL = "SELECT * from user"
myrs.Source = mySQL
Set myrs.ActiveConnection = myconn
myrs.CursorLocation = adUseClient
myrs.Open
myrows = myrs.RecordCount

myrs.Close
myconn.Close

Another workaround is to use a SELECT COUNT(*) statement for a similar query to get the correct row count.
0
 

Author Comment

by:CookieMonster9999
ID: 10970139
thanks guys
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Summernote and form validation 10 230
Scheduled IIS .Net2 AppPools recycle and SQL connection Hangs 33 149
Error viewing ASP page 12 178
How to post data to an API using ASP Classic 3 31
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question