3

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(*)'

2
  • 5
    If you don't know the db table names, what do you need to check a connection for? Commented 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. Commented May 15, 2011 at 13:40

3 Answers 3

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.
1

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.

Comments

1

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

select @@VERSION

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.