In this article, I will explain how I encountered the error “SQL Server blocked access to procedure ‘sys.xp_cmdshell’ of component ‘xp_cmdshell’.” Also, I will explain what I did to resolve this error.
Problem:
Recently, when I was working with SQL Server stored procedures, I wanted to create a stored procedure that creates a directory in the local file system. I searched on the web, how to create a folder in the Windows local file system.
I found that there is a system-defined stored procedure in SQL server named xp_cmdshell that we can use to execute the commands on the Windows command line. Therefore, I tried to pass the Windows command to create a folder to the stored procedure xp_cmdshell. But when I tried to create the folder, I got the following error message:

I was trying to execute the command as:
USE master
GO
EXEC xp_cmdshell 'MD "C:/NewFolder"'
Solution: SQL Server blocked access to procedure ‘sys.xp_cmdshell’ of component ‘xp_cmdshell’
After some research on the internet, I found that before using the xp_cmdshell stored procedure, I need to enable it. Also, it is an advanced option. You cannot enable it directly. First, you have to enable the Show Advanced Options. Only then, you can enable the xp_cmdshell.
I used the following commands to enable these options:
EXEC sp_configure 'Show Advanced Options', '1'
RECONFIGURE
GO
EXEC sp_configure 'xp_cmdshell', '1'
RECONFIGURE
GO
After executing the above commands, I was able to resolve the error and I was able to use the xp_cmdshell and created a folder in the local file system.
You may like the following SQL server tutorials:
- SQL Server stored procedure if else
- How to get list of users in SQL Server
- How to view stored procedure in SQL Server
- SQL Server select from stored procedure
- SQL Server stored procedure output parameter
- How to check if SQL Server is running
- SQL Server check user permissions on table
This is how to fix the error, SQL Server blocked access to procedure ‘sys.xp_cmdshell’ of component ‘xp_cmdshell’.

Rajkishore Sahoo is a Microsoft Azure consultant with more than 14 years of hands-on experience building cloud-native data solutions across Azure and AWS, focused on Azure SQL Database, Azure SQL Managed Instance, and the pipelines that connect them to production apps. Day to day, he provisions Azure SQL instances, configures firewalls and connection strings, tunes queries for cloud workloads, and wires databases into Azure Functions and Logic Apps. Read more