Using BCP utility to create a CSV file from SQL Server

  • I am trying to write a CSV file from my SQL Server database. I am using the query:

    DECLARE @bcpCommand varchar(2000)

    SET @bcpCommand = 'bcp " SELECT ISBN, Condition, SKU, SKY FROM [MyDatabase].dbo.booklist" queryout g:\temp\output.csv -c -CACP -t, -T'

    EXEC master..xp_cmdshell @bcpCommand

    I am getting the error message:

    SQLState = 08001, NativeError = 2

    Error = [Microsoft][SQL Native Client]Named Pipes Provider: Could not open a connection to SQL Server [2].

    SQLState = HYT00, NativeError = 0

    Error = [Microsoft][SQL Native Client]Login timeout expired

    SQLState = 08001, NativeError = 2

    Error = [Microsoft][SQL Native Client]An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connecti

    ons.

    NULL

    I have checked and the access is set up for local and remote connections using both TCP/IP and named pipes.

  • You still have to identify the server and, maybe the instance using the -S parameter.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 2 posts - 1 through 1 (of 1 total)

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