Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Data Management

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Your profile

Search

XML Feeds

Google Ads

« SQL Server 2008 Books Online Jan, 2009 download now availableSQL Server Stored Procedure with nvarchar parameter »
comments
Rate Post:
submit to reddit Digg!FacebookDotnetkicks

If you try to execute xp_cmdshell on a fresh install of SQL Server 2005 or 2008 you will be greeted with the following message

Server: Msg 15281, Level 16, State 1, Procedure xp_cmdshell, Line 1
SQL Server blocked access to procedure 'sys.xp_cmdshell' of component 'xp_cmdshell' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'xp_cmdshell' by using sp_configure. For more information about enabling 'xp_cmdshell', see "Surface Area Configuration" in SQL Server Books Online.

This is done for security reasons. I see a bunch of Google searches hitting our site with a search like this: How do I enable xp_cmdshell in SQL Server 2005? Well you can do it two ways; one is with a script and the other with the Surface Configuration Tool
Let's start with the Surface Configuration Tool

Surface Configuration Tool
You have to navigate to the tool from the start button, the path is below
Programs-->Microsoft SQL server 2005-->Configuration Tools-->Surface Configuration Tool

Then select Surface Area Configuration for Features (bottom one)
Expand Database Engine go all the way down to xp_cmdshell and click enable xp_cmdshell and hit apply

SQL Script
To do it with a script use the one below

  1. EXECUTE SP_CONFIGURE 'show advanced options', 1
  2. RECONFIGURE WITH OVERRIDE
  3. GO
  4.  
  5. EXECUTE SP_CONFIGURE 'xp_cmdshell', '1'
  6. RECONFIGURE WITH OVERRIDE
  7. GO
  8.  
  9. EXECUTE SP_CONFIGURE 'show advanced options', 0
  10. RECONFIGURE WITH OVERRIDE
  11. GO

Just so you know you can also use the script to enable xp_cmdshell on SQL Server 2008. The Surface Area Configuration Tool in SQL Server 2008 has been replaced by the SQL Server Configuration Manager.

In SQL Server 2005 and 2008 OPENROWSET is also disabled by default, if you try to run an OPENROWSET query then you will see the following message:

Server: 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', see "Surface Area Configuration" in SQL Server Books Online.

To enable OPENROWSET and OPENQUERY you can use the previous script but instead of 'xp_cmdshell' you will use 'Ad Hoc Distributed Queries'. The script to enable Ad Hoc Distributed Queries is below

  1. EXECUTE SP_CONFIGURE 'show advanced options', 1
  2. RECONFIGURE WITH OVERRIDE
  3. GO
  4.  
  5. EXECUTE SP_CONFIGURE 'Ad Hoc Distributed Queries', '1'
  6. RECONFIGURE WITH OVERRIDE
  7. GO
  8.  
  9. EXECUTE SP_CONFIGURE 'show advanced options', 0
  10. RECONFIGURE WITH OVERRIDE
  11. GO




*** If you have a SQL related question try our Microsoft SQL Server Programming forum or our Microsoft SQL Server Admin forum

About the Author

User bio imageDenis has been working with SQL Server since version 6.5. Although he worked as an ASP/JSP/ColdFusion developer before the dot com bust, he has been working exclusively as a database developer/architect since 2002. In addition to English, Denis is also fluent in Croatian and Dutch, but he can curse in many other languages and dialects (just ask the SQL optimizer) He lives in Princeton, NJ with his wife and three kids.
Social SitingsTwitterFacebookLinkedInHomePageLTD RSS Feed
5847 views
submit to reddit Digg!FacebookDotnetkicks

Comments and Feedback

5 comments

Comment from: Susan [Visitor]
*****
thanks! Script worked like a charm in 2008 - saved for future reference.
07/20/09 @ 16:05
Comment from: king marcus dizon [Visitor]
thanks very musch ...!!!
12/23/09 @ 04:16
Comment from: Steve Daigle [Visitor]
Thanks!
12/23/09 @ 14:44
Comment from: Denise [Visitor]
Can you tell me where to run the script for enabling the xp_cmdshell? I previously used the Surface Area Config with 2005...but we upgraded to SQL 2008 Express and that is no longer there. I dont know where to run the TSQL from?
12/28/09 @ 20:35
Comment from: SQLDenis [Member] Email
Denise, you need to run it from a query window
12/28/09 @ 20:36

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)