开发者

How to check connection to DB without having the db its tables names

开发者 https://www.devze.com 2023-03-05 20:02 出处:网络
The point here is that I don\'t have the data base table开发者_开发技巧 names so please don\'t suggest to choose one table on to do on it \'SELECT COUNT(*)\'This depends on the database, but usually t

The point here is that I don't have the data base table开发者_开发技巧 names so please don't suggest to choose one table on to do on it 'SELECT COUNT(*)'


This depends on the database, but usually there are some tables that always exist or a table isn't even required.

For Oracle:

SELECT 1 FROM dual

For SqlServer:

SELECT 1

Not very elegant, but generally does the job if you know the database brand.


You haven't said what database type it is, but you could use something like DbConnection.GetSchema which is bound to need a working connection. I don't know how heavy a hit that would be though... if you knew more about the database type there may be a simpler "heartbeat" query you could perform.


You could run a command that doesn't query against a table, such as:

select @@VERSION
0

精彩评论

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