Solved

asp query in mysql

Posted on 2004-05-01
14
674 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

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 information …
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/…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

777 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