Method 1: Use a temporary table.
First, create a temporary table with the same field as sp_who, and then assign values using the insert into method, so that you can select this temporary table. The Code is as follows:
Create table # TempTable (spid int, ecid int, status varchar (32), loginname varchar (32), hostname varchar (32), blk int, dbname varchar (32 ), cmd varchar (32), request_id int );
Insert into # TempTable
Exec sp_who;
Select * from # TempTable where [dbname] = 'master ';
Drop table # TempTable
Method 2: Use OPENROWSET
The Code is as follows:
Select * from openrowset ('sqloledb', 'servername'; 'username'; 'Password', 'SP _ wh') where [dbname] = 'master ';
Run the preceding STATEMENT. If the prompt is displayed, SQL Server blocks access to the STATEMENT 'openrowset/OpenDatasource 'of the 'ad Hoc Distributed Queries' component, this component is disabled as part of the server security configuration. The system administrator can enable 'ad Hoc Distributed Queries 'by using sp_configure '. For more information about enabling 'ad Hoc Distributed querys.
You have not configured 'ad Hoc Distributed Queries '. configure it as follows:
Enable Ad Hoc Distributed Queries:
Exec sp_configure 'show advanced options', 1
Reconfigure
Exec sp_configure 'ad Hoc Distributed Queries ', 1
Reconfigure
Then you can run the above Code.
If you want to disable Ad Hoc Distributed Queries after use, run the following code:
Exec sp_configure 'ad Hoc Distributed Queries ', 0
Reconfigure
Exec sp_configure 'show advanced options', 0
Reconfigure