detecting that a SQL db is running

Paul McNett p at ulmcnett.com
Fri Dec 1 15:33:14 EST 2006


bill ramsay wrote:
> none of this matters,  all i am trying to find out is whether or not
> the local MSDE is actually running.

If it is a local MSDE then you may be able to rely on the connection
being refused if the server isn't running.

#-- begin
import socket

host = "127.0.0.1"
port = 1433  ## replace with msde_port, if it differs

s = socket.socket(socket.AF_INET)
try:
	s.connect((host, port))
	print "Server on %s is running" % port
except socket.error, e:
	print "Server on %s appears to be down (%s)" % (port, e)

#-- end

Please note that this is untested and not very well thought through. But
try it and see if it gets you on the right track. If this isn't run
locally, you'll probably need to set the timeout low enough for the
connect call not to appear to hang before returning the timeout error.

-- 
pkm ~ http://paulmcnett.com





More information about the Python-list mailing list