`
wangpengfei360
  • 浏览: 1057908 次
文章分类
社区版块
存档分类
最新评论

Access/MSSQL/Oracle/MySql获取当前用户连接数(downmoon收集)

 
阅读更多

一、MSSQL中可以用sp_who 获取连接的用户名信息,

二、Oracle也有类似的系统函数

  1. SQL>selectcount(*)fromv $session #连接数
  2. SQL>Selectcount(*)fromv $session wherestatus= 'ACTIVE'   #并发连接数
  3. SQL>showparameterprocesses #最大连接
  4. 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:

  1. Sub ShowUserRosterMultipleUsers()
  2. Dim cn As New ADODB.Connection
  3. Dim rs As New ADODB.Recordset
  4. Dim i,j As Long
  5. Set cn=CurrentProject.Connection
  6. 'Theuserrosterisexposedasaprovider-specificschemarowset
  7. 'intheJet4.0OLEDBprovider.YouhavetouseaGUIDto
  8. 'referencetheschema,asprovider-specificschemasarenot
  9. 'listedinADO'stypelibraryforschemarowsets
  10. Set rs=cn.OpenSchema(adSchemaProviderSpecific,_
  11. , "{947bb102-5d43-11d1-bdbf-00c04fb92675}" )
  12. 'Outputthelistofallusersinthecurrentdatabase.
  13. Debug.Printrs.Fields(0).Name, "" ,rs.Fields(1).Name,_
  14. While Not rs.EOF
  15. Debug.Printrs.Fields(0),rs.Fields(1),_
  16. rs.Fields(2),rs.Fields(3)
  17. rs.MoveNext
  18. Wend
  19. End Sub

   Access Web:

  1. 'ThiscodewasoriginallywrittenbyDevAshish.
  2. 'Itisnottobealteredordistributed,
  3. 'exceptaspartofanapplication.
  4. 'Youarefreetouseitinanyapplication,
  5. 'providedthecopyrightnoticeisleftunchanged.
  6. '
  7. 'CodeCourtesyof
  8. 'DevAshish
  9. '
  10. Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
  11. Function fOSUserName() As String
  12. 'Returnsthenetworkloginname
  13. Dim lngLen As Long ,lngX As Long
  14. Dim strUserName As String
  15. strUserName= String $(254,0)
  16. lngLen=255
  17. lngX=apiGetUserName(strUserName,lngLen)
  18. If (lngX>0) Then
  19. fOSUserName=Left$(strUserName,lngLen-1)
  20. Else
  21. fOSUserName=vbNullString
  22. End If
  23. End Function
  24. '********************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}-->
  1. mysql>showprocesslist;
  1. ./mysqladminprocesslist
. / mysqladminprocesslist

例:

C:/Documents and Settings/administrator>mysqladmin processlist

更详细的,查看当前所有连接的详细资料:

./mysqladmin-uadmin-p-h10.140.1.1processlist


只查看当前连接数(Threads就是连接数.):

./mysqladmin-uadmin-p-h10.140.1.1status

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics