开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜