Re: How to check if SQL Server is local or remote



paolo (paolobitech@xxxxxxxxxxxxxxxx) writes:
Hello everyone,

I have a small c#1.1 app that uses an Oledb connection to connect to SQL
Server (2000/2005). What I'd like to know if there is an easy way to
understand if the connection points to a local SQL Server or a remote SQL
Server...

Of course I could inspect the connectionstring and check for (local) or
127.0.0.1 or resolve the machine name...

-- SQL 2000
SELECT net_library FROM master.dbo.sysprocesses WHERE spid = @@spid
-- SQL 2005
SELECT net_transport FROM sys.dm_exec_connections
WHERE session_id = @@spid

If they return LPC (SQL 2000) or "Shared memory" (SQL 2005) you are
connected to the local server. If they don't you are likely to be connected
to a remote server, but since a local connection could be over TCP/IP or
named pipes it's not foolproof.

--
Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
.