Select * from sp_who Solution

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.