企业管理器-》SQLSERVER组-》你的服务器(没有需注册一个)-》管理-》当前活动
解决方案 »
- 大家帮看两个字段作为条件的IN,NOT IN语句如何表示
- 更新数据库语句
- 我怎么获取一张表的所有相关存储过程?在此先谢谢!
- 这种需要用循环计算吗,
- 重装系统后sqlserver反而连不上怎么回事
- 在已经装好msde的前提下,怎么安装企业管理器
- 关于成绩单的问题,寻SQL解决方案,100分最精炼者得!立等!
- 日期转换问题??
- 数据类型 nvarchar 和 date 在 add 运算符中不兼容
- 求一条SQL语句,在线等。。
- 我有Microsoft Visual Studio .NET 2003 可以调试sql 存储过程吗? 指点,谢谢热心的兄弟!
- 恢复数据库时遇到 当试图还原master数据库时,必须以单用户模式。。。。
如果用ado(asp或asp.net连接),也在这里看吧
另外转载 黄山光明顶的 大作:
--先生成一个存储过程:
Create proc usp_getClient_infor
as
set nocount onDeclare @rc int
Declare @RowCount intSelect @rc=0
Select @RowCount=0begin
--//create temp table ,save sp_who information
create table #tspid(
spid int null,
ecid int null,
status nchar(60) null,
loginname nchar(256) null,
hostname nchar(256) null,
blk bit null,
dbname nchar(256) null,
cmd nchar(32)
)--//create temp table save all SQL client IP and hostname and login time
Create table #userip(
[id]int identity(1,1),
txt varchar(1000),
)--//Create result table to return recordset
Create table #result(
[id]int identity(1,1),
ClientIP varchar(1000),
hostname nchar(256),
login_time datetime default(getdate()) )
--//get host name by exec sp_who ,insert #tspid from sp_who,
insert into #tspid(spid,ecid,status,loginname,hostname,blk,dbname,cmd) exec sp_who declare @cmdStr varchar(100),
@hostName nchar(256),
@userIP varchar(20),
@sendstr varchar(100)
--//declare a cursor from table #tspid
declare tspid cursor
for select distinct hostname from #tspid with (nolock) where spid>50
for read onlyopen tspid
fetch next from tspid into @hostName
While @@FETCH_STATUS = 0
begin
select @cmdStr='ping '+rtrim(@hostName)
insert into #userip(txt) exec master..xp_cmdshell @cmdStr
select @RowCount=count(id) from #userip
if @RowCount=2 --//no IP feedback package
begin
insert into #result(ClientIP,hostname) values('Can not get feedback package from Ping!',@hostName)
end
if @RowCount>2
begin
select @userIP=substring(txt,charindex('[',txt)+1,charindex(']',txt)-charindex('[',txt)-1)
from #userip
where txt like 'Pinging%'
insert into #result(ClientIP,hostname) values(@userIP,@hostName)
end
select @rc=@@error
if @rc=0
truncate table #userip --//clear #userIP table fetch next from tspid into @hostName
end close tspid
deallocate tspidselect * from #result with(nolock)drop table #tspid
drop table #userip
drop table #result
end
go--开始查询连接:
exec usp_getClient_infor