1

When I run batch file with:

BCP "SELECT * FROM [KW_GRECOS].[dbo].[V_G076a]" queryout "G:\Bulk\V_G076a_new.bcp" -N -S localhost -T -E
BCP "[KW_GRECOS].[dbo].[hist_V_G076a]" IN "G:\Bulk\V_G076a_new.bcp" -N -S localhost -T -E -b 1000000 -h "CHECK_CONSTRAINTS"

It works perfectly, but when I execute same batch from job in SQL Server Agent:

cmd.exe /c "E:\batch\Bulk_copy.bat"

It's not working:

Date,Source,Severity,Step ID,Server,Job Name,Step Name,Notifications,Message,Duration,Sql Severity,Sql Message ID,Operator Emailed,Operator Net sent,Operator Paged,Retries Attempted 12/21/2017 00:40:37,NightBulk,Error,,DBSERVER,NightBulk,,,The job failed. The Job was invoked by User eTour\ITcom. The last step to run was step 1 (1 Bulk insert). The job was requested to start at step 1 (1 Bulk insert).,00:00:00,0,0,,,,0 12/21/2017 00:40:37,NightBulk,Error,1,DBSERVER,NightBulk,1 Bulk insert,,Executed as user: DBSERVER\ITcom. C:\Windows\system32>BCP "SELECT * FROM [KW_eTour].[dbo].[V_G075a]" queryout "G:\Bulk\V_G075a_new.bcp" -N -S localhost -T -E SQLState = S1000 NativeError = 0 Error = [Microsoft][ODBC Driver 11 for SQL Server]Unable to open BCP host data-file. Process Exit Code 1. The step failed.,00:00:00,0,0,,,,0

Star
  • 3,222
  • 5
  • 32
  • 48
Peter_K
  • 93
  • 1
  • 10

1 Answers1

0

It is due to insufficient permissions.
The SQL Server Agent service-user can not access the file G:\Bulk\V_G075a_new.bcp.

You have the following options:

  • Move the file to a location where the service-user can access it.
  • Modify the NTFS-permissions of the file/folder to allow the SQL Server Agent service-user to access the file
MatSnow
  • 7,357
  • 3
  • 19
  • 31