7

I am getting this Error While I try to do BCP

SQLState = S1000, NativeError = 0

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

This is my code:

DECLARE @dump_data1 varchar(500)

SET @dump_data1 =  'bcp "select * from IDcountries.dbo.IDs$" queryout "\\NetworkLocation\watchdog.xls" -c -S STRIVEDI\SQLEXPRESS -T'

EXEC xp_cmdshell @dump_data1

I do have all the rights on Network Drive.

This code perfectly works fine for destination of my local drive like C:\.

I also tried entering -U and -P options as well. But, no luck

Can someone please help me on this issue?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user2704062
  • 81
  • 1
  • 2
  • 4
  • So if it **works** on your local `C:\` drive - why not just output the file there using `bcp` and then copying it to your network drive?? – marc_s Oct 17 '13 at 20:52
  • http://social.msdn.microsoft.com/Forums/sqlserver/en-US/6eca2d62-eb86-4f23-9b86-6f917017f50c/bcp-utility-via-xpcmdshell-and-network-drive?forum=sqlsecurity – Mike Gardner Oct 18 '13 at 02:48
  • Just because YOU have permissions to the network drive doesn't mean bcp does – user3036342 Apr 24 '14 at 07:07

3 Answers3

3

I also faced the same problem. This seems to be permission of the folder. Edit the Security Tab under Folder Properties and give Modify permission to the user account through which SQL Server services are running in the SQL Server. Normally this user account is named as MSSQLSERVER. This worked fine for me.

Gwenc37
  • 2,064
  • 7
  • 18
  • 22
0

When you have to put file file like BCP result, or a backup in a remote drive, just map this drive into windows don´t work, it must be mapped on SQL Server to!, to do this, try some link like this:

exec xp_cmdshell 'net use p:\ \\Server\Folder\Folder\Folder\ /Domain\Login /Password'

http://social.msdn.microsoft.com/Forums/sqlserver/en-US/6eca2d62-eb86-4f23-9b86-6f917017f50c/bcp-utility-via-xpcmdshell-and-network-drive?forum=sqlsecurity

Mike Gardner
  • 6,611
  • 5
  • 24
  • 34
0

This is usually due to file create/writing permissions on the output target folder. Try to output data to a local folder on your machine to test:

bcp DATABASE.SCHEMA.TABLE out C:\TEMP\filename.dat -T -S SERVER-NAME -n
GBGOLC
  • 520
  • 8
  • 7