Friday, July 13, 2012

Unable to open BCP host data file xp_cmdshell SQL Server 2008

I have a process that created tab delimited text files on a file server which was then loaded to the SQL Server database using xp_cmdshell. The xp_cmdshell is calling the bcp command.


When the server was migrated to SQL Server 2008 and Windows Server 2008 the exec xp_cmdshell started throwing the error "unable to open bcp host data file".

The actual sql that was being executed was 

exec xp_cmdShell 'bcp DataBase.dbo.Table_Name in E:\Folder_Name\File_Name.txt  -c -T -S Server_Name '

To fix this error I had to replace the file path with the UNC path.

exec xp_cmdShell 'bcp DataBase.dbo.Table_Name in \\FileServer_Name\E$\Folder_Name\File_Name.txt  -c -T -S Server_Name '

No comments: