SQL Server administration and T-SQL development, Web Programming with ASP.NET and Javascript, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software Kodyaz Development Resources
Development resources, articles, tutorials, samples, codes and tools for .Net, SQL Server, Vista, etc.


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 that can be used 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 the 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.PNG







Related SQL Resources

SQL Server Articles

SQL Server 2012

SQL Server Tools

SQL Blog

SQL Server 2008 Blog

Certification Exams Blog

Reporting Services Blog

Analysis Services Blog

MS SQL Server Forums



Free Exam Vouchers









Copyright © 2004 - 2012 Eralper Yilmaz. All rights reserved.
Community Server, by Telligent Systems