LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem With ADO connection using MySQL

Hi, I'm having quite a confusing problem using LabSQL to talk to a MySQL database. I've seen a similar question on this forum, but I've got it working, but it's unrepeatable.

LabVEW 8.0 Pro, Windows XP Pro, LabSQL, MySQL has a database with 3 tables created in it.

I'm looping through some directories.
Then looping through a lot of text files in the directory.
Create the ADO connection
Open the connection to the ADO
Check to see if that file has been entered yet
If not I parse the file and INSERT some information into a table which creates a new record
Use the "SELECT @@IDENTITY;" command to get the id of that record
Use that id to reference the two other tables and populate them (if required)
Close the ADO connection
Destroy the ADO connection
Then move on to the next file
And then move on to the next directory.

And as long as the db is empty in the first place this works fine

However, if I run the whole process again, after about half a dozen directories and thousands of files I get the error-
"Error -2146824584 occured at Exception occured in ADODB.connection: Operation is not allowed when object is closed" when it tries to open the connection, having created it without errors!

I thought this might be because I was creating and destroying the ADO connection each time, so I decided to create the connection at the begining of each new directory. and this seemed to fix the problem because I could now rescan the db.

However now something stranger happens.
If I empty the db and start again, I start getting SQL errors. Basically after a while the ADO Recordset Get String starts returning nothing (But not always!!!) It will refuse to execute the SELECT @@IDENTITY command because it says the record doesn't exist (Even though it has just inserted that record)
And ADO functions start failing all over the place, sometimes without generating an error at all.

0 Kudos
Message 1 of 7
(5,421 Views)
Hi Pete,

What version of the .NET framework have you got installed? With database operations you have to be carefull about managing your references. You will have to make sure you close off any queries that return references.

Every time you use a new database now do you get the errors you mentioned? Are all your reported errors from the LabVIEW error cluster? If you have a pre-created database does the program run without problems?

Regards

Jon B
Applications Engineer
NI UK & Ireland
0 Kudos
Message 2 of 7
(5,381 Views)
Hi Jon,

Well, I think I've got it working, but I'm not really happy with my work around.
I tried upgrading to version 2 of .NET (I was using v1.1) But there was no change, I also modified the code so that it destroyed the connection to the ADO after each INSERT and before each get string, but it still failed in the middle of the same directory.

I've just inserted a wait statment which delays every itteration by 200 ms and that actually seems to have fixed things... I say "Seems" because I've been running the program for 45 minutes now and I'm less than a third of the way through the directories! (previous execute time was 7 mins)
This delay occured to me because the problems started when I changed the parsing sequence to improve the speed of the opperation.

However, this is not exactly an ideal sollution... Do you think the problem is with the ActiveX "connection" or the actual database connection?

Any help would be appreciated because the running speed is now immpractical and I'm not sure why this should have worked.

Thanks - Pete
0 Kudos
Message 3 of 7
(5,370 Views)
Hi Again Pete,

Are you using the Database connectivity toolkit or just the straight ActiveX calls using the ADO API?

Regards

Jon B
Applications Engineer
NI UK & Ireland
0 Kudos
Message 4 of 7
(5,351 Views)
Hi Jon,

I'm using ActiveX directly. It's almost as if the invoke node is completing and returning control before the actual opperation is complete.
I think that when the database was empty, the action of writing to the db slowed each itteration down so the system didn't crash.
 I've now got the delay down to 50mS and the program can now populate the db from scatch as well as re-scan the directories and make updates. but I thought the whole point was that the ActiveX object should handle any timing issues.
It just doesn't make me very confident of the stability of the application, which is intended to be fired off un-manned by the task scheduler.
0 Kudos
Message 5 of 7
(5,348 Views)
Hi Pete,

Sorry for the delay in reply, (I had written a reply earlier but only just found out it didn't get posted properly). I think the problems miht be just down to the ActiveX API, have you tried using the Database connectivity toolkit? It uses the ADO API but has a comprehensive LabVIEW wrapper around it. for more information on it see the link bellow:

http://zone.ni.com/devzone/cda/tut/p/id/3563

regards

Jon B
Applications Engineer
NIUK & Ireland
0 Kudos
Message 6 of 7
(5,303 Views)
Hi I am trying to interface a database in access and Labview.I have seen the "ADODB" control property being used in many of the exampmples usinf ADO to connect to the database.I have been trying to locate the "ADODB" control property but havent been able to.The ActiveX function under the connectivity function would just give me the normal automation open/close,automation reference but nothinh about the ADO DB control properties.Shall be glad to recieve some help.
 
Thanking you in anticipation
0 Kudos
Message 7 of 7
(5,066 Views)