一、MSSQL中可以用sp_who 获取连接的用户名信息,
二、Oracle也有类似的系统函数
- SQL>selectcount(*)fromv $session #连接数
- SQL>Selectcount(*)fromv $session wherestatus= 'ACTIVE' #并发连接数
- SQL>showparameterprocesses #最大连接
- SQL>altersystemsetprocesses=valuescope=spfile;重启数据库 #修改连接
<!-- {cps..0}-->
SQL
>
select
count
(
*
)
from
v$session#连接数
SQL
>
Select
count
(
*
)
from
v$session
where
status
=
'
ACTIVE
'
#并发连接数
SQL
>
showparameterprocesses#最大连接
SQL
>
alter
system
set
processes
=
valuescope
=
spfile;重启数据库#修改连接
三、Access下有以下几种思路:
第一:直接看ldb文件,有几行就有几个连接
格式基本上是
hostname workgroupUserId
第二: 用vbscript
有两段代码可以参考:
Microsoft:
- Sub ShowUserRosterMultipleUsers()
- Dim cn As New ADODB.Connection
- Dim rs As New ADODB.Recordset
- Dim i,j As Long
- Set cn=CurrentProject.Connection
- 'Theuserrosterisexposedasaprovider-specificschemarowset
- 'intheJet4.0OLEDBprovider.YouhavetouseaGUIDto
- 'referencetheschema,asprovider-specificschemasarenot
- 'listedinADO'stypelibraryforschemarowsets
- Set rs=cn.OpenSchema(adSchemaProviderSpecific,_
- , "{947bb102-5d43-11d1-bdbf-00c04fb92675}" )
- 'Outputthelistofallusersinthecurrentdatabase.
- Debug.Printrs.Fields(0).Name, "" ,rs.Fields(1).Name,_
- While Not rs.EOF
- Debug.Printrs.Fields(0),rs.Fields(1),_
- rs.Fields(2),rs.Fields(3)
- rs.MoveNext
- Wend
- End Sub
Access Web:
- 'ThiscodewasoriginallywrittenbyDevAshish.
- 'Itisnottobealteredordistributed,
- 'exceptaspartofanapplication.
- 'Youarefreetouseitinanyapplication,
- 'providedthecopyrightnoticeisleftunchanged.
- '
- 'CodeCourtesyof
- 'DevAshish
- '
- Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
- Function fOSUserName() As String
- 'Returnsthenetworkloginname
- Dim lngLen As Long ,lngX As Long
- Dim strUserName As String
- strUserName= String $(254,0)
- lngLen=255
- lngX=apiGetUserName(strUserName,lngLen)
- If (lngX>0) Then
- fOSUserName=Left$(strUserName,lngLen-1)
- Else
- fOSUserName=vbNullString
- End If
- End Function
- '********************CodeEnd**************************
<!-- {cps..2}-->
'
ThiscodewasoriginallywrittenbyDevAshish.
'
Itisnottobealteredordistributed,
'
exceptaspartofanapplication.
'
Youarefreetouseitinanyapplication,
'
providedthecopyrightnoticeisleftunchanged.
'
'
CodeCourtesyof
'
DevAshish
'
Private
Declare
Function
apiGetUserNameLib
"
advapi32.dll
"
Alias_
Function
fOSUserName()
As
String
'
Returnsthenetworkloginname
Dim
lngLen
As
Long
,lngX
As
Long
Dim
strUserName
As
String
strUserName
=
String
$(
254
,
0
)
lngLen
=
255
lngX
=
apiGetUserName(strUserName,lngLen)
If
(lngX
>
0
)
Then
fOSUserName
=
Left
$(strUserName,lngLen
-
1
)
Else
fOSUserName
=
vbNullString
End
If

EndFunction
'
********************CodeEnd**************************
四、MySql
<!-- {cps..3}-->
或
.
/
mysqladminprocesslist
- mysql>showprocesslist;
- ./mysqladminprocesslist
.
/
mysqladminprocesslist
例:
C:/Documents and Settings/administrator>mysqladmin processlist
更详细的,查看当前所有连接的详细资料:
./mysqladmin-uadmin-p-h10.140.1.1processlist
只查看当前连接数(Threads就是连接数.):
./mysqladmin-uadmin-p-h10.140.1.1status
本文介绍了如何在MS SQL Server、Oracle、Access及MySQL等数据库中查询当前的连接状态和并发连接数,提供了具体命令和示例代码。
1771

被折叠的 条评论
为什么被折叠?



