Using bcp to import data error message

  • I have to use bcp to import a text file from my computer. I am getting the above error and not sure why. Here is my code and any help is appreciated.

    bcp tempdb.dbo.DimProducts in

    "c:\Users\Shay\Documents\DimProducts.txt" -T -c

  • There's no error message listed. What's the error?

  • I apologize here is the error message.

    Msg 102, Level 15, State 1, Line 1

    Incorrect syntax near '.'.

  • Hope this helps :

    http://msdn.microsoft.com/en-us/library/ms162802.aspx

    Cheers,
    - Win.

    " Have a great day "

  • The syntax should be:

    bcp "tempdb.dbo.DimProducts" in "c:\Users\Shay\Documents\DimProducts.txt" -T -c

  • The following article has additional information on the BCP Utility:

    http://www.simple-talk.com/sql/database-administration/working-with-the-bcp-command-line-utility/

    For better, quicker answers on T-SQL questions, click on the following...
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • bcp [tempdb].[dbo].[DimProducts] in

    "c:\Users\Shay\Documents\DimProducts.txt" -c -t

    You don't use BCP from Query Analyzer. You run it from a command-line window.

    you should use -c and not -C. The spacing should be OK, though.

    I have not tested this, but still a hope..

    Cheers,
    - Win.

    " Have a great day "

  • Denny,

    if we use this from analyzer it wil throw error as its a command not sql syntax.

    bcp "tempdb.dbo.DimProducts" in "c:\Users\Shay\Documents\DimProducts.txt" -T -c

    Msg 156, Level 15, State 1, Line 1

    Incorrect syntax near the keyword 'in'.

    Cheers,
    - Win.

    " Have a great day "

  • As stated this shouldn't be run from Query Analyzer. It should be run from a command prompt on the machine's console which has the file on it. If the file is on a network share you'll probably want to specify the network path instead of a local drive.

  • I can not get this to work for nothing. I tried putting the code in the command prompt and it just keeps opening up the data in notepad.

  • What is the syntax?

    Could you include the DDL and the Data for the file so that I can test?

    For better, quicker answers on T-SQL questions, click on the following...
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • mzzzshay (9/12/2011)


    I can not get this to work for nothing. I tried putting the code in the command prompt and it just keeps opening up the data in notepad.

    Please post the exact syntax you are running in the command window.

  • I gave you an example early on that was based on the Adventureworks2008 Database.

    If I'm not familiar with something and I'm getting errors, I have tried running the example.

    Often this points you in the right direction.

    Did you take the time to read the article that I posted?

    Just stating I can't get it to work does not provide any insight.

    http://www.simple-talk.com/sql/database-administration/working-with-the-bcp-command-line-utility/

    For better, quicker answers on T-SQL questions, click on the following...
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • MrDenny, thanks for continuing to try to help me.

    This is my exact code that I am copying to the dos command prompt

    bcp DimProducts in Documents\DimProducts.txt -T -c

    This is the error message I am now getting:

    SQLState = $0002, NativeError = 208

    Error = [Microsoft][SQL Server Native Client 10.0][SQL Server] Invalid obeject name 'DimProducts'.

  • bcp DimProducts in Documents\DimProducts.txt -T -c

    This is the error message I am now getting:

    SQLState = $0002, NativeError = 208

    Error = [Microsoft][SQL Server Native Client 10.0][SQL Server] Invalid obeject name 'DimProducts'.

    OK, this is because BCP doesn't know which database to find your table in. You've got two options (I'll show you both below). The first is to include the database own schema name (usually dbo) in the first parameter after BCP. Assuming that the database is called MyDatabase and the schema is dbo it would look like this.

    bcp MyDatabase.dbo.DimProducts in Documents\DimProducts.txt -T -c

    The second option is to use the -d parameter. Again assuming that the database is named MyDatabase and the owner is dbo.

    bcp dbo.DimProducts in Documents\DimProducts.txt -T -c -d MyDatabase

    Either option will work. Personally I prefer the first one.

Viewing 15 posts - 1 through 15 (of 21 total)

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