SQL SERVER – FIX: Msg 15281 – SQL Server Blocked Access to STATEMENT ‘OpenRowset/OpenDatasource’ of Component ‘Ad Hoc Distributed Queries’

SQL
1 Comment

I wrote a blog earlier about reading data from excel via SQL Server. This was done using ‘OpenRowset. One of my blog readers sent an email to me that they were getting an error. In this blog, we would see how to fix Msg 15281 – SQL Server blocked access to STATEMENT ‘OpenRowset/OpenDatasource’ of component ‘Ad Hoc Distributed Queries’

SQL SERVER - FIX: Msg 15281 - SQL Server Blocked Access to STATEMENT 'OpenRowset/OpenDatasource' of Component 'Ad Hoc Distributed Queries' blockedaccess

Here is the query which my blog reader was using.

SELECT * FROM OPENROWSET(
'Microsoft.ACE.OLEDB.12.0'
,'Excel 12.0;Database=\\\\FileServer\\ExcelShare\\HRMSDATA.xlsx;HDR=YES;IMEX=1'
,'SELECT * FROM [EMPMASTER$]')

the error message while running the query is as follows.

Msg 15281, Level 16, State 1, Line 1

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.

SOLUTION/WORKAROUND

Here is the T-SQL which can be used to enable the usage of open rowset.

EXEC sp_configure 'show advanced options', 1
RECONFIGURE WITH OVERRIDE
GO
EXEC sp_configure 'ad hoc distributed queries', 1
RECONFIGURE WITH OVERRIDE
GO

After this, he was able to pull data from excel sheet to SQL Server. Well, this was quite a simple solution for a complicated looking problem. If you have alternative suggestions, please do share.

Reference: Pinal Dave (https://blog.sqlauthority.com)

, , , ,
Previous Post
SQL SERVER – Installation Stuck at Offline Installation of Microsoft Machine Learning Server Components
Next Post
SQL SERVER – xp_create_subdir() Returned Error 183, ‘Cannot Create a File When that File Already Exists

Related Posts

1 Comment. Leave new

Leave a Reply

Menu