Check if an instance of SQL Server is present on the local computer?
I would like to detect if the SQL Server is connected to the local machine or not. I know that there are many ways to identify the names of the instances of the server \ instance of SQL Server when you connect to it, but there are so many different ways to determine the name of the server, I do not want to do a comparison between the IP-addresses, host names, (local)
, LocalHost
, .
, etc.
Is there anything in SQL Server (any 2000+ versions) where I can check if an instance is on the local machine or not without comparing my own?
a source to share
SELECT Case when HOST_NAME()=
Case When CharIndex('\',@@SERVERNAME)=0 then @@SERVERNAME else LEFT(@@SERVERNAME,CharIndex('\',@@SERVERNAME)-1) end
then 'local' else 'remote' end
since @@ SERVERNAME is defined during installation and can be changed (even sp_addserver) which you prefer:
SELECT Case when HOST_NAME()=SERVERPROPERTY('MachineName') then 'local' else 'remote' end
a source to share