bcp says invalid character when importing data for a tutorial

Sam of Simple Samples 5,546 Reputation points
2021-05-06T04:25:40.833+00:00

See Create tables, bulk import, and query data - Learn. It describes use of bcp to import the data. When I do I get:

Error = [Microsoft][ODBC Driver 13 for SQL Server]Invalid character value for cast specification  

for each of the 5 records. I think I followed the instructions.

My mytable.fmt file is:

14.0
2
1 SQLCHAR 0 12 "," 2 MyColumn1 ""
2 SQLCHAR 0 50 "\r\n" 1 MyColumn2 SQL_Latin1_General_CP1_CI_AS

My mydata.csv is as provided in the tutorial. I was a little confused because the tutorial says bash but I assume I should use a normal Windows command prompt. So I created a cmd file with the following:

bcp Tutorials.dbo.mytable in mydata.csv -f mytable.fmt -S samstutorialserver.database.windows.net -U Sam -P password -F 2  

Did I miss seeing something in the tutorial or is the tutorial unclear or something else? What is causing the error?

SQL Server | Other
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 122.6K Reputation points
    2021-05-06T04:52:13.847+00:00

    Probably you should not change the order of columns if it is not needed. Try this .fmt file:

    14.0
    2
    1 SQLCHAR 0 12 "," 1 MyColumn1 ""
    2 SQLCHAR 0 50 "\r\n" 2 MyColumn2 SQL_Latin1_General_CP1_CI_AS


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.