Results 1 to 2 of 2
  1. #1
    Join Date
    May 2005
    Location
    Bangalore, India
    Posts
    35

    Unanswered: SQLState=S1000, Proc to Export Tables into Flat Files

    Hi,

    I am trying to create a Procedure that will export all the tables present in the database to corresponding flat files. The below procedure builds fine but gives a run-time error as below:

    SQLState = S1000, NativeError = 0
    Error = [Microsoft][ODBC SQL Server Driver]Unable to open BCP host data-file
    NULL

    What am I missing?

    Divakar

    CREATE Procedure BCP_Text_File_5
    AS
    BEGIN
    Declare @table varchar(100)
    Declare @FileName varchar(100)
    Declare @str varchar(1000)

    DECLARE export_cursor CURSOR LOCAL FOR
    select name from dbo.sysobjects where xtype = 'U' and name = 'TestTable'

    open export_cursor
    FETCH NEXT FROM export_cursor INTO @table


    BEGIN
    set @FileName = 'D:\SqlData\' + @table + '.txt'
    set @str='Exec Master..xp_Cmdshell ''bcp "Select * from '+ db_name() + '..' + @table + '" queryout "'+ @FileName + '" -U sa -P sa -c'''
    EXEC (@str)

    FETCH NEXT FROM export_cursor INTO @table

    END
    CLOSE export_cursor
    DEALLOCATE export_cursor
    end

  2. #2
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    try printing instead of executing your string to see if you are forming valid bcp commands.
    If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry. Earnest Hemingway, A Farewell To Arms.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •