View Data From Mysql Database


Recommended Posts

hye ..i have a database with data already logging there..i just want the DaqFactory open the database so that i can manipulate the data in DaqFactory. i installed the ODBC 32 bit on my pc and here is the details

 

dsn=DBTesting

user=user

pssw=pssw

database=testing

table on the mysql database=my_chart_data

and the table contains

 

category     value1    value2

7.30 am       23.0         24.5

7.40 am       20.19       21.22

 

i try logging some random data to the other  blank database (testing2) as mention in user guide and it successfully logging. the problem is when i try to open the database and view the data, i keep getting the 01002 error. here are my script for the SEQUENCES;

 

global string DSN

global string user

global string pssw

global string DATABASE

private handle

private result

 

DSN=DBTesting

user=user1

pssw=psswd

DATABASE=testing

 

private handle=DB.OpenEx("DBTesting","user1","psswd","testing")

private handle=DB.OpenEx("DBTesting")

 

is there any steps that i forgot to configure? tq :)

 

Link to comment
Share on other sites

Are you sure about the error code?  These error codes are right out of ODBC so you can google them.  And when do you get the error?  With the OpenEx()?  

 

BTW: you don't need to call OpenEx() twice, and in fact you shouldn't.  Also, these lines: 

 

DSN=DBTesting

user=user1

pssw=psswd

DATABASE=testing

 

won't work because DBTesting, user1, etc. aren't symbols in the system.  I think you want quotes around them.

 

And the parameters you passed in OpenEx() don't match what you said your user and password were above.

 

Next, you don't pass the database name to openEx(), just the ODBC data source name and credentials.  These credentials are just for the ODBC connection and have nothing to do with any credentials you may have implemented in MySQL.  Those you would specify when you setup the actual ODBC data source, along with the database you are trying to access.

 

Finally, I've had more success with the 3.51 mysql ODBC driver then the 5.x versions, but that doesn't mean the 5.x ones won't work.

 

Oh, and one more important point: if you are using a 64 bit version of Windows, you have to make sure and use the 32 bit ODBC drivers because DAQFactory is a 32 bit application (most applications are).  If you just go to control panel, you'll get the 64 bit ODBC configuration tool and any data sources you create there will be invisible to 32 bit apps like DAQFactory.   The 32 bit version is in C:\Windows\SysWOW64\ODBCCP32.CPL.  I personally created a shortcut to it and added it to my Administrative tools folder so I have easy access to both 32 bit and 64 bit forms. 

 

This last point, BTW, applies to any application, not just DAQFactory.  If the tool you want to access your database with is 32 bit, you have to use the 32 bit ODBC drivers.

Link to comment
Share on other sites

okay..now i change all..sorry for the careless.

 

global string DATABASE

 

DATABASE='DBTesting'

DB.Open("DBTesting")

 

i only put DB.Open("DBTesting") and no error come out from Alert..just the comm monitor display RX:N\000\000\000\....mysql_native_password\00

 

dont understand what happen actually..i try do some searching about the mysql_native_password things but yeah..still confuse..YES, i confirm that i use 32 bit ODBC with my 32 bit window

 

i just want to pull out the data from mysql database..hope u can guide me..

Link to comment
Share on other sites

The comm monitor displayed something?  That doesn't make sense as the comm port isn't connected in any way with ODBC, but perhaps you have something else.

 

You likely just want:

 

global dbase = db.Open("DBTesting")

global data = db.queryToClass(dbase, "select * from myTable")

 

then data will be a class with your data.  So if myTable has a field named "myfield" you could access the data with:

 

data.myField

Link to comment
Share on other sites

global dbase = db.Open("DBTesting")

global data = db.queryToClass(dbase, "select * from temperature")

 

is myTable is the table in my database? and when i click begin sequence..no error..can i assume the DF connect suncessfully to mysql?

so how can i display my data on the DF?

Link to comment
Share on other sites

In your code, temperature is the table.  The database is specified in the ODBC setup so is never specified in DAQFactory.  DBTesting is the name of the ODBC data source (not the database).  The data is in the variable "data".  So if you want to access a field named "myField" it would be:

 

data.myField

Link to comment
Share on other sites

okay..so the data.myField should be in the mychannel_0 event or what?or it should be in another sequence ?

->did the protocol for mychannel_0 should be the odbc protocol?or just using the null protocol?

->the sequence status is stopped right after i click the sequence begin.

i try to create new protocol but i cant find any .dds or .ddp file for odbc..should i create by my self?can i get from somewhere?

Link to comment
Share on other sites

Reading from an ODBC database isn't a channel type of activity.  Channels are for data coming from hardware devices.  There are ways to create script to read databases and then fill channels, but I don't think you really need that.  ODBC is definitely unrelated to protocols, so that is definitely the wrong track.

 

You should be able to put that code in a normal sequence, then you can use data.myField wherever you want in the user interface to view the contents.

Link to comment
Share on other sites

thanks..i refer to this thread

http://www.azeotech.com/board/index.php?/topic/3384-reading-sql-server-2005-odbc/  and i change some parts of the script and the sequence is running without error..i assume the script is working.now i need to create aTABLE so that all the data display on that table dynamically..any suggestion would be great for me..thnks a lot. :)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.