Using the SERVER_NAME Keyword
The SERVER_NAME keyword returns the name of the database
server associated with a CONNECT or DATABASE statement. GET DIAGNOSTICS
updates the SERVER_NAME field when any of the following events occur:
- A CONNECT statement successfully executes.
- A SET CONNECTION statement successfully executes.
- A DISCONNECT statement successfully terminates the current connection.
- A DISCONNECT ALL statement fails.
The SERVER_NAME field is not updated, however, after these
events:
- A CONNECT statement fails.
- A DISCONNECT statement fails (but this does not include the DISCONNECT ALL statement).
- A SET CONNECTION statement fails.
The SERVER_NAME field retains the value set in the previous SQL statement. If any of the preceding conditions occur on the first SQL statement that executes, the SERVER_NAME field is blank.