开发者

Any alternative of mysql_ping for MSSQL?

开发者 https://www.devze.com 2023-04-01 00:03 出处:网络
I\'m opening the persistent connection with the DB开发者_如何学Go on MSSQL server over an unstable channel and would like to check the connection status before the transaction starts (it is a daemon s

I'm opening the persistent connection with the DB开发者_如何学Go on MSSQL server over an unstable channel and would like to check the connection status before the transaction starts (it is a daemon service which remains always active).

In case of mysql, postgresql I've used the beautiful mysql_ping and pg_ping to be sure the connection is OK. Any ideas who to accomplish it with M$SQL?


No, there is no built-in function like that for MSSQL. Your best bet would be to run a cheap SQL select such as SELECT GETDATE() NULL on the open connection, catch any SqlException that is thrown, check and re-establish the connection if needed.

0

精彩评论

暂无评论...
验证码 换一张
取 消