Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL statement to check for connectivity?

Tags:

c#

sql

I'm looking for a dummy SQL statement that will work from a C# SQL connection to check for connectivity.

Basically I need to send a request to the database, I don't care what it returns I just want it to be successful if the database is still there and throw an exception if the database isn't.

The scenario I'm testing for is a loss of connectivity to the database, where the SQLConnections State property seems to still be "Open" but there is no connectivity.

like image 402
Omar Kooheji Avatar asked Nov 04 '08 12:11

Omar Kooheji


1 Answers

You could do this:

Select 1

Ok, how about sending an empty string or blank space. Those are valid commands for Sql Server.

like image 50
Amy B Avatar answered Nov 15 '22 22:11

Amy B