SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software SQL Server and T-SQL Development Tutorials
Development resources, articles, tutorials, code samples and tools and downloads for ASP.Net, SQL Server, R Script, Windows, Windows Phone, AWS, SAP HANA and ABAP, like SAP UI5, Screen Personas, etc.

Install SQL Server 2019
download SQL Server 2019
download SQL Server 2017
download SQL Server 2016
download SQL Server 2014

How to Create Folder from SQL Server sys.xp_create_subdir Extended Stored Procedure

In this SQL Server tutorial for SQL developers, I'll show T-SQL codes to create folder using SQL Server sys.xp_create_subdir extended stored procedure.
Here is the first sql xp_create_subdir example for SQL Server professionals.

EXEC master.sys.xp_create_subdir 'C:\SQLDatabases\Test\'

In order to create file system directory successfully, access permissions for the SQL user must be granted correctly.
For example, in my SQL Server development environment, I have configured required permission for the "C:\SQLDatabases\" folder.
On the other hand when I set the xp_create_subdir argument as "C:\TestFolder\" for example,

Msg 22048, Level 16, State 1, Line 0
xp_create_subdir() returned error 5, 'Access is denied.'

In order to resolve Access is denied error related with xp_create_subdir usage, you should grant Write permission to SQLServerMSSQLUser (SQLServerMSSQLUser$SQLServerInstance) user. You can use the Windows Explorer and grant required permission on the root folder where you want to create file folders using xp_create_subdir.

folder permissions select MSSQLServer user

Giving Write permission is enough to create folder using sys.xp_create_subdir extended stored procedure.

security permissions for MSSQLServer user

Related SQL Resources

SQL Server Articles

SQL Server 2012

SQL Server Tools

SQL Blog

MS SQL Server Forums

Copyright © 2004 - 2020 Eralper YILMAZ. All rights reserved.
Community Server by Telligent Systems