Skip to main content

SQL 2005/2008 Ad hoc access to OLE DB provider has been denied

I have a previous post on enabling adhoc access for SQL 2000 (, SQL 2005 and 2008 are a little different.
SQL 2005/2008 returns the following:
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', see "Surface Area Configuration" in SQL Server Books Online.
To enable OpenRowset and OpenDatasource:
  • Launch the "SQL Server 2005 Surface Area Configuration" tool.
  • Click "Surface Area Configuration for Features"
  • Select "Server Name > Database Engine > Ad Hox Remote Queries"
  • Tick "Enable OPENROWSET and OPENDATASOURCE" support.
  • Click OK

After completing the above steps you might see the following error when you run the query again:

Ad hoc access to OLE DB provider 'MSDASQL' has been denied. You must access this provider through a linked server.

To resolve this:

  • Open regedit
  • Expand "HKEY_LOCAL_MACHINE\Software\Microsoft\Microsoft SQL Server\MSSQL.1\Providers" – depending on how many instances you have installed you may have MSSQL.1, MSSQL.2 etc – the instance name is shown as the (Default) value under each branch – check this to ensure you are editing the settings for the correct instance.
  • If it isn't already present add a new DWord setting under MSDASQL with a name of DisallowAdhocAccess and value of 0.


Popular posts from this blog

Take website screenshot using ASP.NET

Utilising a hidden web browser control it is possible to take a screenshot of any website. The code shown below is based on an article at  (sorry the site now appears to be offline May 2012) but I have translated it from VB.NET to C# and will work in .NET so theoretically for any Windows or ASP.NET web project. using System; using System.Drawing; using System.Drawing.Imaging; using System.Windows.Forms; using System.Diagnostics; namespace WebsiteScreenshot { public class GetImage { private int s_Height; private int s_Width; private int f_Height; private int f_Width; private string myURL; public int ScreenHeight { get { return s_Height; } set { s_Height = value; } } public int ScreenWidth { get { return s_Width; } set { s_Width = value; } } public int ImageWidth { get { return f_Width; } set { f_Width = value; } } public int ImageHeight { get { return f_Height; } set { f_Height = value; } } public string Websit

Ad hoc access to OLE DB provider has been denied

Using post SP2 SQL 7 (+ 2000 etc) attempting to access an OLEDB data source using OPENROWSET can produce the slightly spurious error: Ad hoc access to OLE DB provider 'MSDASQL' has been denied. You must access this provider through a linked server. In usual Microsoft style the message doesn't really mean what it says. From SQL 7 SP2 onwards MS by default blocked ad hoc query access with OLEDB. As the message suggests you could setup a linked server but that can be a real pain. Alternatively if you need ad hoc access server wide you could turn on ad hoc access for the SQL server you are using, explained in MS speak here: Ah, but it's not that simple. A little more witchcraft is required. The following registry settings can be used to enable ad hoc access: REGEDIT4 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\Providers] "DisallowAdhocAccess"=dword:00000000 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLSer

Compress and de-compress strings in C#

A collection of resources on compressing and encrypting strings in C#. Microsoft documentation on the System.IO.Compression.GZipStream class: Helpful example class utilising GZip: The GZipStream class is predominantly used for file compression but can be used efficiently for compressing strings of 300-400 characters or more. Below 300 characters there isn’t any measurable gain from the compression and for particularly short strings the compressed version may in fact be larger. Class provided by C Sharp Help : using System.IO.Compression; using System.Text; using System.IO; public static string Compress(string text) {     byte[] buffer = Encoding.UTF8.GetBytes(text);     MemoryStream ms = new MemoryStream();     using (GZipStream zip = new GZipStream(ms, CompressionMode.Compress,