2

如何仅从 SQL Server 2005 中的查询中选择服务器的 IP 地址?

4

3 回答 3

1

尝试这个:

SELECT CONNECTIONPROPERTY('local_net_address') AS local_net_address,

或者:

SELECT SERVERPROPERTY(N'MachineName');

或者:

SELECT @@SERVERNAME;
于 2013-04-11T07:19:07.467 回答
0

在这里,您可以借助函数:

CREATE FUNCTION [dbo].[GetCurrentIP] ()
RETURNS varchar(255)
AS
BEGIN
    DECLARE @IP_Address varchar(255);

    SELECT @IP_Address = client_net_address
    FROM sys.dm_exec_connections
    WHERE Session_id = @@SPID;

    Return @IP_Address;
END
于 2013-04-11T06:54:31.690 回答
0

这是我找到的最好的解决方案,希望对你有帮助

SELECT SERVERNAME = CONVERT(NVARCHAR(128),SERVERPROPERTY('SERVERNAME'))   
,LOCAL_NET_ADDRESS AS 'IPAddressOfSQLServer'  
,local_tcp_port  AS 'PortNumber' 
 FROM SYS.dm_exec_connections 
 WHERE local_net_address IS NOT NULL
 AND session_id IS NOT NULL
 GROUP BY LOCAL_NET_ADDRESS,local_tcp_port
于 2017-04-07T21:18:08.073 回答