Share via

SSIS Bulk Insert to table with identity

Leau Bee Lin 91 Reputation points
Sep 17, 2021, 2:16 AM

Bulk Insert task with the following and getting error.

1) Destination Table is [dbo].[table1]

CREATE TABLE [dbo].[table1](
[ID] [bigint] IDENTITY(1,1) NOT NULL,
[Column1] nvarchar NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

2) Source Connection - File is file1.csv

field1,field2,field3
value1,value2,value3

3) Format
132941-image.png

4) Options - Enable identity insert

5) Error
Error: 0xC002F304 at Bulk Insert Task Identity, Bulk Insert Task: An error occurred with the following error message: "Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".The OLE DB provider "BULK" for linked server "(null)" reported an error. The provider did not give any information about the error.Bulk load: An unexpected end of file was encountered in the data file.".

SQL Server Integration Services
SQL Server Integration Services
A Microsoft platform for building enterprise-level data integration and data transformations solutions.
2,666 questions
0 comments No comments
{count} votes

Accepted answer
  1. ZoeHui-MSFT 41,446 Reputation points
    Sep 22, 2021, 3:19 AM

    Hi @Leau Bee Lin

    Thanks for your reply, I fully understand your need now.

    Please create Destination Table with below code.

    CREATE TABLE [dbo].[table1](  
    [Column1] [nvarchar](max) NULL,  
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]  
    

    Format as below.

    134068-screenshot-2021-09-22-110838.jpg

    In the package, we may need to use Execute SQL Task to add the IDENTITY ID column.

    ALTER TABLE table1 ADD ID  [bigint] IDENTITY(1,1) NOT NULL  
    

    134146-untitled.png

    And then we could get the table1 in the database as you need.

    134192-screenshot-2021-09-22-111828.jpg

    Regards,

    Zoe


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
    Hot issues October


5 additional answers

Sort by: Most helpful
  1. ZoeHui-MSFT 41,446 Reputation points
    Sep 17, 2021, 2:46 AM

    Hi @Leau Bee Lin

    The ColumnDelimiter in Format should be Comma(,) cause the (CSV) file is a delimited text file that uses a comma to separate values.

    In addition, if the csv file has three columns, the table1 should also have three columns or the bulk insert will be like below.

    132908-screenshot-2021-09-17-104604.jpg

    Regards,

    Zoe


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
    Hot issues October

    0 comments No comments

  2. Leau Bee Lin 91 Reputation points
    Sep 17, 2021, 2:57 AM

    132935-image.png

    This is the correct result. Content of each row in csv will be in Column1. ColumnDelimiter will be Tab.
    How do you get the above result as I am getting error? What is missing?


  3. Leau Bee Lin 91 Reputation points
    Sep 17, 2021, 6:23 AM

    Got the below error after setting ColumnDelimiter to "Comma (,)".

    Error: 0xC002F304 at Bulk Insert Task Identity, Bulk Insert Task: An error occurred with the following error message: "Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".The OLE DB provider "BULK" for linked server "(null)" reported an error. The provider did not give any information about the error.Cannot bulk load because the maximum number of errors (10) was exceeded.Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 11, column 1 (ID).Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 10, column 1 (ID).Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 9, column 1 (ID).Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 8, column 1 (ID).Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 7, column 1 (ID).Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 6, column 1 (ID).Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 5, column 1 (ID).Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 4, column 1 (ID).Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 3, column 1 (ID).Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 2, column 1 (ID).Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 1, column 1 (ID).".


  4. Leau Bee Lin 91 Reputation points
    Sep 17, 2021, 8:59 AM

    Previous error was meant for another csv file.

    With file1.csv as below,
    field1,field2
    value1,value2

    I am getting this error.
    Error: 0xC002F304 at Bulk Insert Task Identity, Bulk Insert Task: An error occurred with the following error message: "Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 2, column 1 (ID).Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 1, column 1 (ID).".


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.