BCP Error

  • I have a procedure that executes the xp_cmdshell extended proc.  The execution string run BCP which executes a procedure and outputs the resultset as a file.  It has been working fine for several months.  I made a small change to the underlying procedure (the one that ends with a select statement and returns results).

    The string used for xp_cmdshell looks like this:

    bcp.exe "exec Test32..sp_GLExport '6/30/06', 'lwol', '0', '1', '0' " queryout "d:\Service\GL_Exports\glexport.TXT" -c -S"TestServer"  -U"sa"  -P"sapass"

     

    The underlying procedure (sp_GLExport) works correctly and returns a resultset.  Note that the resultset is a single column 178 characters wide.

     

    The proc now returns the following error:

    SQLState = S1010, NativeError = 0

    Error = [Microsoft][ODBC SQL Server Driver]Function sequence error

    After much research I really do not have much to go on to solve this.  Any help would be greatly appreciated.

  • This was removed by the editor as SPAM

  • A bit late maybe...

    I had a similar problem caused by a sproc parameter declared as a VARCHAR(MAX). Changing MAX to 20 stopped the error.

  • Spoke too soon. I was calling procedures from the main procedure that would output the result set. The only way I could get rid of the errors was to break things up so only one stored procedure was being executed by bcp at a time. Very strange...I was also getting "Error = [Microsoft][SQL Native Client]Protocol error in TDS stream" errors as well, even though execution from sqlcmd or SSMS worked fine.

  • I had this problem. Our bcp was calling a stored procedure. Our stored procedure had 2 queries but only one was run determined by an input parameter. When run the bcp we got these errors particularly on the second. Turns out bcp runs a precursor of some sort to determine number of columns, if you have two queries that could output, it can cause a number of different errors.

    In short, make sure your stored procedure only has one output (comment the rest out). If this is your problem resolve by either separating your stored procedure, or by making sure all out putting procedures return the same column structure.

    Note on errors: this error and a number of others (syntax type errors) can be a result of this. Also, the output may only have one row of results where there should have been more. A bit of wierdness with BCP and this case.

    Hopefully this saves some users some time.

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

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