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(*)'
-
5If you don't know the db table names, what do you need to check a connection for?R. Martinho Fernandes– R. Martinho Fernandes2011-05-15 13:14:08 +00:00Commented May 15, 2011 at 13:14
-
@Martinho Fernandes - I want to create a generic Base Class that manage my connection to the DB. I give it the connection string but to give it a table name just for checking the connection seems exaggerated to me.Erez– Erez2011-05-15 13:40:53 +00:00Commented May 15, 2011 at 13:40
Add a comment
|
3 Answers
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.
1 Comment
R. Martinho Fernandes
I disagree with "not very elegant". Ok, the Oracle version is ugly, but that's because of the hack that is
dual. But SELECT 1 is extremely elegant.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.