Hi,
I am trying to write a script in SQL Server 2008 Express Edition for creating a folder in a network drive and then Backup database in that folder. I have tried using the following
DECLARE @DBFolderName sysname
DECLARE @DirPath nvarchar(500)
DECLARE @DirTree TABLE (subdirectory nvarchar(255), depth INT)
-- 2 - Initialize variables
SET @DBFolderName = 'XXX'
SET @DirPath = N'\\ipl20\D\Abcd\' + @DBFolderName
-- 3 - @DataPath values
INSERT INTO @DirTree(subdirectory, depth)
EXEC master.sys.xp_dirtree @DirPath
-- 4 - Create the @DataPath directory
IF NOT EXISTS (SELECT 1 FROM @DirTree WHERE subdirectory = @DBFolderName)
EXEC master.dbo.xp_create_subdir @DirPath
BACKUP DATABASE XXX
TO DISK = @DirPath
WITH INIT,SKIP
While trying to create the above folder a following error appears
xp_create_subdir() returned error 161, 'The specified path is invalid.'
Please do suggest me how to do the same.