Unable to open BCP host data-file error

  • This code be used to pass variable value to text , when run it give

    Error = [Microsoft][ODBC SQL Server Driver]Unable to open BCP host data-file

    the code is

    DECLARE @FileName varchar(50),

    @bcpCommand varchar(2000),

    @CTX_TRAILER varchar(40)

    set @CTX_TRAILER ='HIHIHI'

    SET @FileName = 'D:\alianz\output\CEMTXOUT_ALIANZ'

    SET @bcpCommand = 'bcp " select '''+ @CTX_TRAILER +'''" queryout "'

    SET @bcpCommand = @bcpCommand + @FileName + '" -U xxx -P xxxxxxx -c'

    EXEC master..xp_cmdshell @bcpCommand

    select @bcpCommand

    how can fix that

  • Is this file definately accessible by the server hosting your SQL instance.

    Don't forget, "'D:\alianz\output\CEMTXOUT_ALIANZ'" is referring to the D: drive on the server, not the workstation you are connecting from.

    Also, does the file have a suffix e.g. .txt or .csv

  • Ian Scarlett (7/6/2009)


    Is this file definately accessible by the server hosting your SQL instance.

    Don't forget, "'D:\alianz\output\CEMTXOUT_ALIANZ'" is referring to the D: drive on the server, not the workstation you are connecting from.

    Also, does the file have a suffix e.g. .txt or .csv

    thanx for this hint , so what if I want to run it on my D drive on my pc

  • ali.m.habib (7/6/2009)


    so what if I want to run it on my D drive on my pc

    You will need to refer to it using UNC notation (\\mypc\d\\alianz\output\CEMTXOUT_ALIANZ)... which means sharing your D: drive, and making sure it is accessible by the SQL Server service startup account

    or

    Copy it from your PC to the server

    or

    Copy it from your PC to somewhere that is accessible from both your PC and the server

    or

    Run BCP at your PC

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply