Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

Having problem using BCP via xp_cmdshell.

I exported the table data to a file as .dat but when I try to import the file to a new table, I am getting the below error. The SQL Server service and the account that I am using has full access on that drive. I am not sure why I am still having issues.

Error = [Microsoft][SQL Server Native Client 10.0] Unable to open BCP host data-file.

Here are the scripts that I am running.

exec master..xp_cmdshell 'BCP database.dbo.tabel OUT d:\tabledata.dat -T -c' 
exec master..xp_cmdshell 'BCP database.dbo.tabelnew IN d:\tabledata.dat -T -c' 
share|improve this question
Have you tried executing these commands directly from the command line instead of using xp_cmdshell? –  Mike Fal Dec 10 '13 at 21:42
In my experience, BCP generally requires that the file be local to the destination server. Is that the case? –  Jon of All Trades Dec 10 '13 at 23:13
Try `exec master..xp_cmdshell 'BCP database.dbo.tabel OUT d:\somefolder\tabledata.dat -T -c'. That should work. Note somefolder. –  Kin Dec 11 '13 at 4:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.