Gianluca,
I haven't purposely overlooked your example.
The check_db_state output file was getting this message
"HResult 0x2, Level 16, State 1
Named Pipes Provider: Could not open a connection to SQL Server [2].
Sqlcmd: Error: Microsoft SQL Server Native Client 10.0 : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..
Sqlcmd: Error: Microsoft SQL Server Native Client 10.0 : Login timeout expired."
Hence the errorlevel was always 1.
I have kept that in a template directory to look at as I think it is a neat way of doing it and as you say the better way.
I don't mind if you want to help fix that error and we'll get it working that way.
But I would also like to get the procedural way working as well as we got so os close to getting that working...For now I'll try adding parameter to the stored procedure. it would be nice to see both ways working if ok with you?
Finishing off today now I have to say you have both been very helpful, and I trully appreciative there are some very decent human beings out there helping dummy newbie users like us.