Solved

asp query in mysql

Posted on 2004-05-01
14
678 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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!

 
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

Technology Partners: 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

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 was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

724 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