Solved

asp query in mysql

Posted on 2004-05-01
14
672 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
 
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now