Source: Monitor All current user information connected to SQL Server
if object_id('P_getlinkinfo','P') is not NULL Drop procP_getlinkinfoGoCreate procP_getlinkinfo@dbnamesysname=NULL,--to check the name of the library, it is implied that all@includeip bit=0 --whether IP information is displayed as beginDeclare @dbid int Set @dbid=db_id(@dbname)if object_id('tempdb: #tb') is not NULL Drop Table#tbif object_id('tempdb: #ip') is not NULL Drop Table#ipCreate Table#tb (IDint Identity(1,1), dbname sysname,hostnamenchar( -), LoginNamenchar( -), net_addressnchar( A), Net_ipnvarchar( the), Prog_namenchar( -)) Insert into#tb (hostname,dbname,net_address,loginname,prog_name)Select distincthostname,db_name(dbid), Net_address,loginame,program_name fromMaster.. sysprocesseswhereHostname!="' and(@dbid is NULL ordbid=@dbid) if @includeip=0 GotoLb_show--do not show ipDeclare @sql varchar( -),@hostname nchar( -),@id int Create Table#ip (hostnamenchar( -), avarchar( $)) DeclareTbcursorLocal for Select distinctHostname from#tbOpenTBFetch Next fromTb into @hostname while @ @fetch_status=0 begin Set @sql='Ping'+@hostname+'-a-n 1-l 1' Insert#ip (a)execMaster.. xp_cmdshell@sql Update#ipSetHostname=@hostname whereHostname is NULL Fetch Next fromTb into @hostname End Update#tbSetNet_ip=leftAPatindex('%:%'A-1) from#tb AInner Join (SelectHostname,a=substringAPatindex('Ping statistics for%:%'A+ -, -) from#ipwhereA like'Ping statistics for%:%') b onA.hostname=b.hostname lb_show:SelectId,dbname,hostname,loginname,net_address,net_ip,prog_name from#tbEnd Go execP_getlinkinfo@dbname='Master',@includeip=1
Msg 15281, Level 16, State 1, procedure xp_cmdshell, line 1th SQL Server blocked access to the process ' Sys.xp_cmdshell ' for component ' xp_cmdshell ' because this component has been shut down as part of this server's security configuration. System administrators can enable ' xp_cmdshell ' by using Sp_confi gure. For more information about enabling ' xp_cmdshell ', see "surface Area Configurator" in SQL Server Books Online.
SELECT * fromsys.configurationsORDER byname; sp_configure'Show advanced Options',1;GoReconfigure;Gosp_configure'xp_cmdshell',1;GoReconfigure;Go
Monitor all current user information connected to SQL Server