03-25-2008 09:02 PM
03-26-2008 01:46 PM
To find out what's causing the too many connections error, you can query SELECT USER(), SHOW PROCESSLIST, SHOW STATUS or SHOW TABLE STATUS. These will return information about the connected users, open connections and threads. Since the problem could arise from the db connection, the selected table or an active query, check the MySQL manual to see which of these queries will generate the exact information you need to find out which of your LV programs is leaving connections open. You may have to make each one of your LV programs a separate user to identify the exact source. You'll also need SUPER or PROCESS privileges to see system wide.
Once you identify the culprit, you can use one of the FLUSH, RESET or KILL queries to terminate the problem connections. You could build a LabSQL VI to do this every time before opening and closing a session or use this procedure to respond to an error message from the db but you should examine your programs to find out why you are running out of connections. Multiple calls to the same table without a corresponding close, especially within loops are the first and most obvious place to look.
Another possibility is that your programs are genuinely busy querying the db and using up all the available connections. If this is the case, you can increase the number of allowed simultaneous connections to the server. Again, you should track down why this is happening. This could be a LabVIEW, a database design or MySQL issue. The MySQL Manual has some good information on optimizing the database server and queries.
03-26-2008 07:59 PM
Hi John CS
thanks alot. I will look into your advices.
Clement
03-28-2008 01:17 AM
03-28-2008 04:13 AM
03-31-2008 02:48 AM
MySQL will return a new ID for each new connection. If you open connections without a corresponding close for each one, the behaviour you observed is normal. The Connector doesn't care who asked or how often, only how many open connections there are. The thread command SLEEP means that the thread is waiting for the client to send a new statement to it. The connection is still open and needs to be closed in order to release the thread.
The behaviour you are experiencing is caused by the nested layers of control that exist between your VI and the MySQL database and back. Queries go through LabVIEW, ADODB, ODBC and MySQL and back to process a transaction. Sometimes the interactions are not so obvious. For example, when using the ADODB Close Method on a database opened with ODBC drivers, the thread doesn't terminate because the ODBC database connection process keeps running. To close the connection successfully, you must terminate the connection from the calling application. You may also want to investigate using
In our case, LabVIEW further complicates things because it keeps refnums open until they are explicitly closed by the Close Reference function or when the VI terminates normally. So if you use the LabSQL Close Connection.vi to close the connection, ODBC will keep the reference open as long as the VI runs. The LabSQL Destroy.VI will take care of this. There are timeouts in ADODB, ODBC and MySQL that can also terminate the connection, but not every time. If ADODB detects a pending transaction, it will keep the connection open it is resolved. You may also want to investigate using LabSQL Recordset Move Last.vi to force a close.
Each component tries to simplify the process by hiding some of these activities from the user. For both the ADODB and ODBC components, Microsoft recommends that you keep the connection time as short as necessary and to explicitly close the connection when you are done with it. With this in mind, I think that all three of the scenarios meet this in the circumstances you present.
The safest thing to do is to always have a Destroy Connection.vi matched to each Open Connection.vi.
In your examples, a shift register is not necessary for the refnums. The error cluster, on the other hand, should be wired to a shift register to pass any error from one iteration to the next. Checking for an error in each iteration and stopping the loop on an error is a good idea here.
03-31-2008 07:50 PM
Hi JohnCS,]
Thanks
Clement