I am trying to move a file from a network drive to another server and when I execute this statement. I get an output of

The user name or password is incorrect

DECLARE @SourceFile AS VARCHAR(500);  
DECLARE @DestinationFile AS VARCHAR(500);  

SET @SourceFile='\\SHDVNFDBV1\shared-backup\netFORUM_Archive.bak';
SET @DestinationFile ='J:\netFORUM_Archive_TEST.bak';

SET @Cmd = 'COPY ' + @SourceFile + ' ' + @DestinationFile; 

EXEC master.dbo.xp_cmdshell @Cmd
  • also tried GRANT EXECUTE ON xp_cmdshell TO UserName Feb 5, 2016 at 15:04
  • 1
    The service account for SQL Server needs write access to both \\SHDVNFDBV1\ (who named that server???) and J:\ - this is not something you can fix inside SQL Server with GRANT. Also writing to a drive root may be problematic due to UAC and other OS restrictions, so consider using J:\some_sub_folder\... Feb 5, 2016 at 15:13

1 Answer 1


You should check if you have permissions or not

exec xp_cmdshell 'net use \\SHDVNFDBV1\shared-backup\  /USER:domain\username Passw0rd1'

Do not copy to root directory as @AaronBertrand mentioned.

As a side note, why are you using SQL Server to do filesystem tasks? This should be done by PowerShell e.g. Copy-Item c:\scripts\test.txt c:\test

  • 1
    Agreed, this is not a job for T-SQL in the first place. Feb 5, 2016 at 15:44
  • @AaronBertrand Just curious - is this listed in your Bad Habits series ? If not, this is a good candidate to include - Just a suggestion :-)
    – Kin Shah
    Feb 5, 2016 at 15:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.