tags:

views:

330

answers:

4

In my win app - I want to display an information (or db icon) if the database server is not reachable. But i dont want to wait the 30sec timeout. The user can configure server, user, pw in my options dialog. So, is there a way in subsonic to check very fast if an db connection works?

A: 

You could find out some information on the protocol and simply emulate that using TCP sockets. So it's like telneting to a web server and issuing HTTP commands. However, you would do commands appropriate for your sort of database. Doing this you can avoid whatever timeout is built into the driver or whatever. Alternatively, you could simply connect to the IP:Port using TCP and see if anybody is listening. As far as with Subsonic, no.

BobbyShaftoe
Until now i simply fired a "TOP 1" select to subsonic for one of my tables and catched the sqlexception. So i got the information.. but with the db connection timeout delay...
isepise
Yeah, if you're saying you're still getting the timeout; I would go with the port connection option. Don't bother with running any protocol commands, just see if you can connect. That's just me though.
BobbyShaftoe
My current solution is to first Ping the server (System.Net.NetworkInformation.Ping). Result is Ok or IPStatus.TimedOut or PingException. If the ping is ok I check the DB Server itself with a dummy low commandtimeout db command.
isepise
That's ok except that what if ICMP is blocked? Connecting to the port will always work if it is available. But it's not a bad solution.
BobbyShaftoe
I will consider the port method.. thanks
isepise
A: 

Can you set the connection timeout low - see here for an exmaple, or perhaps do it on a background thread, and let the user know it's being tried.

Preet Sangha
+2  A: 

You could create a simple ping stored procedure and then execute that with a low timeout on the SQL command, something like:

SubSonic.StoredProcedure sp = SPs.PingStoredProcedure();  
sp.CommandTimeout = 2;  
sp.Execute();
Adam
+1  A: 

In the current revision (521) there is an IsOnline() method you can use with the repository pattern. It currently always returns true (see here)...but once that's fixed, you could use the overloaded method that passes in a connection string with a short timeout.

http://code.google.com/p/subsonicproject/source/browse/trunk/SubSonic/Sql%20Tools/SubSonicRepository.cs

ranomore