Operation stopped while importing CSV file into SQL server
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).
"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.
I had the same problem:
Error 0xc02020a1: Data Flow Task 1: Data conversion failed. The data conversion for column "target" returned status value 4 and status text "Text was truncated or one or more characters had no match in the target code page.".
The solution was to go to "Advanced" and change the column width to 255.