Article ID: 327489 - Last Review: October 30, 2003 - Revision: 3.5 HOW TO: Use the DisallowAdHocAccess Setting to Control Access to Linked ServersThis article was previously published under Q327489 On This PageSUMMARY
This article explains how to disable ad hoc queries that use the OPENROWSET or the OPENDATASOURCE functionality in SQL Server.
Disable Transact-SQL StatementsThere are two ways that you can disable Transact-SQL statements that use ad-hoc connection strings with specific OLE DB providers in the OPENROWSET and OPENDATASOURCE functions:
Specify the DisallowAdHocAccess Property When You Create a Linked ServerWhen you create a linked server on a computer that is running SQL Server, you can specify the DisallowAdHocAccess property for the OLE DB provider. To do so, follow these steps:
Manually Modify the Registry and Add the DisallowAdHocAccess ValueAfter a linked server is saved, the DisallowAdHocAccess property can only be set through a registry setting.NOTE: The two illustrations are just examples of how you can change the OLE DB provider for both ODBC and for the SQL Server OLE DB provider. If you want to use a different OLE DB provider, then you must modify that Provider's entry. Important This section, method, or task contains steps that tell you how to modify the registry. However, serious problems might occur if you modify the registry incorrectly. Therefore, make sure that you follow these steps carefully. For added protection, back up the registry before you modify it. Then, you can restore the registry if a problem occurs. For more information about how to back up and restore the registry, click the following article number to view the article in the Microsoft Knowledge Base: 322756
(http://support.microsoft.com/kb/322756/
)
How to back up and restore the registry in Windows Add the DisallowAdHocAccess ValueTo add the DisallowAdHocAccess value, follow these steps:
Modify an Existing DisallowAdHocAccess ValueTo modify an existing DisallowAdHocAccess value, follow these steps:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\<Instance
Name>\Providers\MSDASQL NOTE: With the DisallowAdHocAccess property set to 1, SQL Server does not allow ad hoc access through the OPENROWSET and the OPENDATASOURCE functions against the specified OLE DB provider. If you try to call these functions in ad hoc queries, you will receive an error message similar to:
Server: Msg 7415, Level 16, State 1, Line 1
Ad hoc access to OLE DB provider 'Microsoft.Jet.OLEDB.4.0' has been denied. You must access this provider through a linked server.
REFERENCES
SQL Server Books Online; topics: "Configuring OLE DB providers for Distributed Queries"; "OPENROWSET Transact-SQL Reference"; "OPENDATASOURCE Transact-SQL Reference"
| Article Translations
|
Back to the top
