Please help to use BCP

  • I am using following command

    DECLARE @FileName varchar(50),

    @bcpCommand varchar(2000)

    SET @FileName = REPLACE('c:\authors_'+CONVERT(char(8),GETDATE(),1)+'.txt','/','-')

    SET @bcpCommand = 'bcp "SELECT * FROM [demo2_rmps]..mms_menu " queryout "'

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

    EXEC master..xp_cmdshell @bcpCommand

    But it is given following error

    SQLState = 08001, NativeError = 17

    Error = [Microsoft][ODBC SQL Server Driver][Shared Memory]SQL Server does not exist or access denied.

    SQLState = 01000, NativeError = 2

    Warning = [Microsoft][ODBC SQL Server Driver][Shared Memory]ConnectionOpen (Connect()).

    NULL

    Please help me

    Thnks

    KD

  • See if xp_cmdshell is enabled or not

    you can find that in surface area config,

    Using xp_cmdshell you can only run one command at a time unless you give "&" between the commands.

    example:

    xp_cmdshell 'ping ip_add1 & ping ip_add2'

    Tanx 😀

  • Try this....

    Microsoft SQL Server 2005 --> Configuration Tools -->

    SQL Server Configuration Manager -->

    SQL Server 2005 Network Configuration --> Enable TCP-IP

  • Thanks for reply

    I want to know how we can make a CSV file instead of Txt file

  • Give .csv extension instead of .txt

    Tanx 😀

  • panwar.jt (6/24/2009)


    I am using following command

    DECLARE @FileName varchar(50),

    @bcpCommand varchar(2000)

    SET @FileName = REPLACE('c:\authors_'+CONVERT(char(8),GETDATE(),1)+'.txt','/','-')

    SET @bcpCommand = 'bcp "SELECT * FROM [demo2_rmps]..mms_menu " queryout "'

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

    EXEC master..xp_cmdshell @bcpCommand

    But it is given following error

    SQLState = 08001, NativeError = 17

    Error = [Microsoft][ODBC SQL Server Driver][Shared Memory]SQL Server does not exist or access denied.

    SQLState = 01000, NativeError = 2

    Warning = [Microsoft][ODBC SQL Server Driver][Shared Memory]ConnectionOpen (Connect()).

    NULL

    Please help me

    Thnks

    KD

    You are missing a switch on the BCP command line that tells bcp the server, -Sservername[\instancename]

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

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