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
Development resources, articles, tutorials, code samples, tools and downloads for ASP.Net, SQL Server, Reporting Services, T-SQL, Windows, AWS, SAP HANA and ABAP

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\'
Code

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.'
Code




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



SQL Server

SQL Server 2019 Installation
download SQL Server 2019
download SQL Server 2017
download SQL Server 2016
download SQL Server 2014
download SQL Server 2012
MacOS ve SQL Server 2019


Copyright © 2004 - 2021 Eralper YILMAZ. All rights reserved.