キャンセル
次の結果を表示 
次の代わりに検索 
もしかして: 

database connection status indicator

解決済み
解決策を見る

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,

0 件の賞賛
メッセージ1/8
5,351件の閲覧回数

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.

メッセージ2/8
5,338件の閲覧回数

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.

0 件の賞賛
メッセージ3/8
5,336件の閲覧回数
解決策
受理者 guangdew1

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.

 

dbcheck.png

 

=====================
LabVIEW 2012


メッセージ4/8
5,328件の閲覧回数

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.

0 件の賞賛
メッセージ5/8
5,315件の閲覧回数

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?

0 件の賞賛
メッセージ6/8
4,768件の閲覧回数

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.

0 件の賞賛
メッセージ7/8
4,753件の閲覧回数

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.

0 件の賞賛
メッセージ8/8
4,741件の閲覧回数