05-01-2011 03:56 AM
I want to put something on the front panel of my program that will show the database connection status. I'm thinking of asking to list tables (it doesn't have to be displayed), if the connection is no longer good, it will show error. I tried it and I think it works okay but I don't know whether this is proper way to do it, maybe there are better ways there, could someone point it out for me?
Best regards,
解決済! 解決策の投稿を見る。
05-01-2011 09:42 AM
Do you really need to have a "live" indicator always showing the current connection status of the database? If you do then you really only need to open a connection to the database make sure it returns no error and then close the connection and do this on a regular basis.
But why not just display an error message if and when you try to connect to the database and it doesn't work?
Chris.
05-01-2011 10:40 AM
Hi Chris,
To have a "live" indicator to show the status of database connection is my intention, but I don't know what is the proper way to do it. I don't know whether it's okay to keep on opening and closing the connection is a good practice.
Maybe I'll just do it as you suggested, I'll show something on the front panel only if error happens.
Thanks for your help.
05-01-2011 12:13 PM - 編集済み 05-01-2011 12:18 PM
You definately do not want to open and close the connection. Maybe it will fail but the "real" connection is fine. Maybe the real one failed but this other open and close works. This could happen if the server has the max number of connections.
Does your connection just go away?
A simple way to check the connection is to just have a loop that periodically executes a meaningless statement.
05-01-2011 01:30 PM
Hi Steve,
This is a remote connection and some times the operator doesn't know what is happening if the server is down but the program is very dependent on the server to run.
You solution works OK, thanks for your help.
06-27-2017 06:06 PM
it works for a while until SQL closes the connection? I guess I am better off opening and closing the connection? But the sema vi has another connection to the same database, would that still stay open?
06-28-2017 10:06 AM - 編集済み 06-28-2017 10:08 AM
This is a very old thread so you should create a new post if you still have questions. You can reference this thread for context if you want.
06-28-2017 05:05 PM
I put a disconnect in and it seems to work. MySQL you can log in multiple times with the same user. So one loop just checks tor DB connection, the other does the logging.