SQL Error – SQL Server blocked access to STATEMENT ‘OpenRowset/ OpenDatasource’ of component ‘Ad Hoc Distributed Queries’
Today while executing a Stored Procedure which internally executes a remote query via Linked Server, I got following error:
Msg 50000, Level 16, State 127, Procedure spExecureRemoteQuery, Line 50
SQL Server blocked access to STATEMENT ‘OpenRowset/OpenDatasource’ of component ‘Ad Hoc Distributed Queries’ because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of ‘Ad Hoc Distributed Queries’ by using sp_configure. For more information about enabling ‘Ad Hoc Distributed Queries’, search for ‘Ad Hoc Distributed Queries’ in SQL Server Books Online.
The above clearly means that the “Ad Hoc Distributed Queries” option is disabled on the database instance.
–> Run below Query to check if this property is disabled, if will show you 0 value under Config & Run value columns:
sp_configure 'show advanced options', 1 GO EXEC sp_configure GO
–> To enable it run the below Query:
sp_configure 'Ad Hoc Distributed Queries', 1 GO RECONFIGURE WITH OverRide GO EXEC sp_configure GO
…the value under Config & Run value columns shows 1, means that now the Property is enabled and you can execute your Remote/Linked-Server queries.
Share this:
- Click to share on Facebook (Opens in new window) Facebook
- Click to share on X (Opens in new window) X
- Click to email a link to a friend (Opens in new window) Email
- Click to print (Opens in new window) Print
- Click to share on LinkedIn (Opens in new window) LinkedIn
- Click to share on Reddit (Opens in new window) Reddit
Related
Apache Spark books:
- Spark: The Definitive Guide
- Learning Spark 2Ed
SQL Server - Certification exam books:
- TSQL: 70-761 , 70-762
- DBA: 70-764 , 70-765
- DW/BI: 70-767
SQL Tags
annual report Apache Spark APPLY Operator Azure Databricks BCP Clustered Index ColumnStore Index Cpp CROSS APPLY Databricks Denali Download SQL Server Excel Exception Handling FileTables Graphics in Cpp Hekaton Hekaton 2014 IDENTITY In-Memory Tables Install SQL Server Java Applet Programs Java Basic Programs Java File Handling Java IO Programs Java OO Programs JSON JSON SQL Linked Server msdb MSDN TSQL forum multiple values to Stored Procedures PRIMARY KEY Python Runnable Interface sp_configure SQL Agent SQL Server 2012 SQL Server 2014 SQL Server 2016 SQL Server 2017 SQL Server Certification SQL Server Interview Questions SQL Server on Linux Stored Procedure Temporary Tables TRY-CATCH WordPress Annual Report XML XML SQLCategories
- AI & ML (1)
- Big Data (13)
- Apache Spark (6)
- Hadoop (5)
- DBA Stuff (37)
- Interview Q (8)
- Microsoft Azure (37)
- Azure Data Factory (1)
- Azure DevOps (2)
- Cosmos DB (5)
- Databricks (7)
- MS BI (9)
- Analysis Services (1)
- DW and BI (1)
- Integration Services (1)
- Power BI (4)
- Reporting Services (2)
- Tabular Model (1)
- Others (205)
- Blockchain (1)
- Certifications (9)
- Cloud Computing (1)
- Cpp (32)
- Cpp Graphics (21)
- Excel (10)
- Informatica (5)
- Java (56)
- Linux (8)
- Microsoft (15)
- MS.net (2)
- Oracle (1)
- Powershell (3)
- Python (6)
- Reviews (5)
- Security (1)
- Spark SQL (3)
- SQL Server (9)
- SQLwithManoj (12)
- Uncategorized (7)
- VBA Macro (1)
- Visual Studio (1)
- Windows (6)
- SQL Server Conferences (1)
- SQL Server Internals (85)
- Datatypes (5)
- DB Concepts (28)
- Indexes (11)
- JOINS (4)
- ML Python (2)
- SQL DB Engine (8)
- SQL Server Migration (1)
- SQL Server Upgrade (1)
- Stored Procedures (11)
- tempdb (3)
- XML (16)
- SQL Server Questions (41)
- SQL Server Versions (139)
- SQL Azure (5)
- SQL Server 2005 (7)
- SQL Server 2008 (5)
- SQL Server 2012 (33)
- SQL Server 2014 (18)
- SQL Server 2016 (50)
- SQL Server 2017 (20)
- SQL Server 2019 (2)
- SQL Server 2022 (1)
- SQL Server 2025 (1)
- SQL Server Express (1)
- T SQL (184)
- Differences (31)
- JSON (6)
- Misconception (7)
- Optimization Performance (14)
- SQL Basics (15)
- SQL Built-in Functions (6)
- SQL Errors (45)
- SQL Tips (67)
- SQL Trivia (9)
Archives
Top Posts
- DB Basics - SQL Server JOINS and Types
- SQL Error - The database owner SID recorded in the master database differs from the database owner SID
- more examples on querying XML ...with CROSS APPLY & XQuery - in SQL Server
- SQL Basics - Difference between WHERE, GROUP BY and HAVING clause
- SQL Server 2016 RTM full and final version available - Download it now !!!
- SQL Error - The operation cannot be performed on a database with database snapshots or active DBCC replicas
- SQL Error - The server may be running out of resources, or the assembly may not be trusted with PERMISSION_SET = EXTERNAL_ACCESS or UNSAFE
- What is Lambda Architecture? and what Azure offers with its new Cosmos DB?
- SQL DBA - Move tempDB to another drive in simple steps
- Query XML with different languages or different UNICODE encodings [UTF-8 & UTF-16]
Blog Stats, since Aug 2010
- 5,143,302 hits
StatCounter …since April 2012

Leisure blog: Creek & Trails
- NMDC Hyderabad Marathon – My first 42k FM, cramps, training and fuelling
- Singapore (Part 2) – 6 days itinerary, sightseeing & attractions
- Singapore (Part 1) – Tickets, Visa, Hotel, Forex Card/Cash, Metro/Bus cards
- I got full refund of my flight tickets during COVID lockdown (AirIndia via MakeMyTrip)
- YouTube – Your Google Ads account was cancelled due to no spend
- YouTube latest update on its YPP (YouTube Partner Program) which may affect your channel
- Starting your own blog !!!
- How to file ITR (Income Tax Return) online AY 2017-18 (for simple salaried)
- Scam – Become a kin/hier and earn a fortune – via LinkedIn and Email
- Places to visit in and around Vizag (aka Visakhapatnam)
Disclaimer
This is my personal blog site.
The opinions expressed here represent my own and not those of my employer. For accuracy and official reference refer to MS Books On Line and/or MSDN/TechNet.
My employer do not endorse any tools, applications, books, or concepts mentioned on the blog. I have documented my personal experience on this blog.





