检查谁连接我的服务器,可以用PowerShell脚本来实现。 
脚本如下: $Server='SERVERNAME'
$SMOServer=New-ObjectMicrosoft.SQLServer.Management.SMO.Server$Server
#connectionandquerystuff
$ConnectionStr="Server=$Server;Database=Master;IntegratedSecurity=True"
$Query="EXECsp_who2"
$Connection=new-objectsystem.Data.SQLClient.SQLConnection
$Table=new-object"System.Data.DataTable"
$Connection.connectionstring=$ConnectionStr
try{
$Connection.open()
$Command=$Connection.CreateCommand()
$Command.commandtext=$Query
$result=$Command.ExecuteReader()
$Table.Load($result)
}
catch{
#Showerror
$error[0]|format-list-Force
}
$Title="Dataaccessprocesses ("+$Table.Rows.Count+")"
$Table|Out-GridView-Title$Title
$Connection.close()
|
点击查看更多