Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Operation stopped while importing CSV file into SQL server

Tags:

sql-server

csv

I am trying to import CSV file to SQL server database, with no success. I am still newbie to sql server.

Operation stopped...

  • Initializing Data Flow Task (Success)

  • Initializing Connections (Success)

  • Setting SQL Command (Success)

  • Setting Source Connection (Success)

  • Setting Destination Connection (Success)

  • Validating (Success) Messages

    • Warning 0x80049304: Data Flow Task 1: Warning: Could not open global shared memory to communicate with performance DLL; data flow performance counters are not available. To resolve, run this package as an administrator, or on the system's console. (SQL Server Import and Export Wizard)
  • Prepare for Execute (Success)

  • Pre-execute (Success) Messages

    • Information 0x402090dc: Data Flow Task 1: The processing of file "D:\test.csv" has started. (SQL Server Import and Export Wizard)
  • Executing (Error) Messages

    • Error 0xc002f210: Drop table(s) SQL Task 1: Executing the query "drop table [dbo].[test] " failed with the following error: "Cannot drop the table 'dbo.test', because it does not exist or you do not have permission.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly. (SQL Server Import and Export Wizard)

    • Error 0xc02020a1: Data Flow Task 1: Data conversion failed. The data conversion for column ""Code"" returned status value 4 and status text "Text was truncated or one or more characters had no match in the target code page.". (SQL Server Import and Export Wizard)

    • Error 0xc020902a: Data Flow Task 1: The "output column ""Code"" (38)" failed because truncation occurred, and the truncation row disposition on "output column ""Code"" (38)" specifies failure on truncation. A truncation error occurred on the specified object of the specified component. (SQL Server Import and Export Wizard)

    • Error 0xc0202092: Data Flow Task 1: An error occurred while processing file "D:\test.csv" on data row 21. (SQL Server Import and Export Wizard)

    • Error 0xc0047038: Data Flow Task 1: SSIS Error Code DTS_E_PRIMEOUTPUTFAILED. The PrimeOutput method on component "Source - test_csv" (1) returned error code 0xC0202092. The component returned a failure code when the pipeline engine called PrimeOutput(). The meaning of the failure code is defined by the component, but the error is fatal and the pipeline stopped executing. There may be error messages posted before this with more information about the failure. (SQL Server Import and Export Wizard)

  • Copying to [dbo].[test] (Stopped)

  • Post-execute (Success) Messages

    • Information 0x402090dd: Data Flow Task 1: The processing of file "D:\test.csv" has ended. (SQL Server Import and Export Wizard)

    • Information 0x402090df: Data Flow Task 1: The final commit for the data insertion in "component "Destination - test" (70)" has started. (SQL Server Import and Export Wizard)

    • Information 0x402090e0: Data Flow Task 1: The final commit for the data insertion in "component "Destination - test" (70)" has ended. (SQL Server Import and Export Wizard)

    • Information 0x4004300b: Data Flow Task 1: "component "Destination - test" (70)" wrote 0 rows. (SQL Server Import and Export Wizard)

like image 341
Bart Avatar asked May 26 '10 04:05

Bart


2 Answers

"Text was truncated or one or more characters had no match in the target code page."

may occur EVEN when:

  • your source flat file is a UNICODE file

AND

  • your target column is defined as nvarchar(max).

This took me a while to figure out.

Cause

SSIS infers data types in the source file from scanning the first N rows and making an educated guess. Due to endlessly repeated attempts to get it to work, it had parked the metadata for the data type (OutputColumnWidth) to 50 characters somewhere along the way, causing truncation internal to the package.

Resolution

Fiddling with the metadata in the Data Source's "Advanced" tab is then what you want to do to resolve the problem. Try to reset the whole thing by playing with the settings in "Suggest Types", or tweak settings on a field-by-field basis. A truly discouraging amount of iterations was needed in my case (broad input file), but eventually you can get it to work.

like image 179
Eoan Avatar answered Oct 20 '22 16:10

Eoan


You really have two major problems in your import:

Error 0xc002f210: Drop table(s) SQL Task 1: Executing the query "drop table [dbo].[test] " failed with the following error: "Cannot drop the table 'dbo.test', because it does not exist or you do not have permission.".

It seems like you're trying to drop a table that doesn't even exist. Solution: just don't do it!

Error 0xc02020a1: Data Flow Task 1: Data conversion failed. The data conversion for column ""Code"" returned status value 4 and status text "Text was truncated or one or more characters had no match in the target code page.".

Your column "Code" obviously is longer than the resulting column that you have in your target table. Check the mappings - maybe this is a very long character string, and the default length for the VARCHAR column in SQL Server is too small. Change the target column's data type to e.g. VARCHAR(MAX) - that gives you 2 GByte of space! That should be enough....

Also it seems that "Code" column contains characters that aren't present in your currently selected code page in SQL Server - can you strip those extra special characters before importing? If not, you might need to use NVARCHAR(MAX) for your target column's data type in order to allow it to use Unicode for its characters (thus supporting even the most exotic of characters in your input string).

like image 26
marc_s Avatar answered Oct 20 '22 17:10

marc_s