[Python] Re: mssql

Nicola Larosa nico a tekNico.net
Gio 27 Lug 2006 16:15:42 CEST


>> Se però il server non è raggiungibile ottengo in output un messaggio
>> del genere:
>>
>> _mssql.error: DB-Lib error message 20009, severity 9:
>> Server is unavailable or does not exist.
>>
>> Come potrei gestire questo errore in maniera "elegante"?

> Non conosco il modulo in questione ma ti potrei consigliare
> 
> import _mssql
> 
> try:
>     mssql=_mssql.connect('127.0.0.1 <http://127.0.0.1>','sa','')
> except:
>     mssql=None

Per favore, no.

Non silenziate gli errori con una except vuota: non saprete più cos'è successo.

Come minimo fate:

try:
    mssql = _mssql.connect('127.0.0.1 <http://127.0.0.1>','sa','')
except Exception, err:
    print err

Meglio ancora specificare l'eccezione:

try:
    mssql = _mssql.connect('127.0.0.1 <http://127.0.0.1>','sa','')
except _mssql.error, err:
    print err

così altre eccezioni non gestite daranno un traceback completo.


Infine, non uso SQL Server ma quel "_mssql" mi puzza di variabile interna.
Non c'è qualcosa di più ufficiale da usare?


-- 
Nicola Larosa - http://www.tekNico.net/

SOAP-based services are called "Web Services" because their proponents
wish to partake of the Web's success -- yet they don't build on its
core technologies, URIs and HTTP. Somehow many have equated SOAP and
Web Services but HTTP has been in Service on the Web for more than a
decade now and has not yet hit its prime. -- Paul Prescod, April 2002



Maggiori informazioni sulla lista Python