如果你用的是sql server 2000 则: adoconnection.commandtext:='Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Data Source=KDYY001\NETSDK;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=KDYY001;Use Encryption for Data=False;Tag with column collation when possible=False';//这是我的sql 2000的信息,要求建立的时候不能选择数据库名 adoquery.sql.add('select name from syslogins');
exec sp_who 不行。它所获得的是进程数,而且active无法区别活动进程数
exec sp_monitor connections 登录或尝试登录 SQL Server 的次数。 只能获得连接次数,而不是当前所连接的用户数, 所以也不行。
上面的不对,用这个: select count(*) from master..sysprocesses where hostname<>''
hlddg(hlddg) 'select name from syslogins'这个也不对只能获得当前允许登录的用户名,如SA等,而不是当前连接在数据库上的用户数。谢谢你们等待>>>>>>>>>
用adoquery来获得当前用户: DECLARE @sys_usr char(30) SET @sys_usr = SYSTEM_USER SELECT 'The current system user is: '+ @sys_usr GO
select count(*) as 连接数 from master..sysprocesses where hostname<>''
select count(*) from master..sysprocesses where hostname<>'' 这个有效,nononono 你能解释一下吗?
这是得到当前SERVER的连接用户数, 能不能定位所接的数据库呢?
你看看 select * from master..sysprocesses 的结果集就明白了。
用adoquery来获得当前用户: DECLARE @sys_usr char(30) SET @sys_usr = SYSTEM_USER SELECT 'The current system user is: '+ @sys_usr GOself.ADOQuery1.RecordCount;不就是当前用户的数量吗!
select dbname = case when dbid = 0 then null when dbid <> 0 then db_name(dbid) end, loginame from master..sysprocesses where hostname is not null group by dbid,loginame
nononono(null,null) 结果集中并没有字段是指明记录是对什么数据库操作的啊。
firetoucher(蹈火者) 非常感谢,但我没看明白dbname从何而来?
我明白了,我需要的是select db_id('数据库名'), loginame from master..sysprocesses where hostname is not null group by dbid,loginame
就可以了。但是名字我几不得了。你可以去看看SQL SERVER的连机帮助。就应该有答案。
如果你用的是sql server 2000 则:
adoconnection.commandtext:='Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Data Source=KDYY001\NETSDK;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=KDYY001;Use Encryption for Data=False;Tag with column collation when possible=False';//这是我的sql 2000的信息,要求建立的时候不能选择数据库名
adoquery.sql.add('select name from syslogins');
connections 登录或尝试登录 SQL Server 的次数。
只能获得连接次数,而不是当前所连接的用户数,
所以也不行。
select count(*) from master..sysprocesses where hostname<>''
DECLARE @sys_usr char(30)
SET @sys_usr = SYSTEM_USER
SELECT 'The current system user is: '+ @sys_usr
GO
这个有效,nononono
你能解释一下吗?
能不能定位所接的数据库呢?
DECLARE @sys_usr char(30)
SET @sys_usr = SYSTEM_USER
SELECT 'The current system user is: '+ @sys_usr
GOself.ADOQuery1.RecordCount;不就是当前用户的数量吗!
select dbname = case
when dbid = 0 then null
when dbid <> 0 then db_name(dbid)
end, loginame from master..sysprocesses where hostname is not null
group by dbid,loginame
loginame from master..sysprocesses where hostname is not null
group by dbid,loginame