'Import Flat File via SSMS to SQL Server fails
When importing a seemingly valid flat file (csv, text etc) into a SQL Server database using the SSMS Import Flat File option, the following error appears:
Microsoft SQL Server Management Studio
Error inserting data into table. (Microsoft.SqlServer.Import.Wizard)
Error inserting data into table. (Microsoft.SqlServer.Prose.Import)
Object reference not set to an instance of an object. (Microsoft.SqlServer.Prose.Import)
The target table may contain rows that imported just fine. The first row that is not imported appears to have no formatting errors.
What's going wrong?
Solution 1:[1]
If the file you're importing is already open, SSMS will throw this error. Close the file and try again.
Solution 2:[2]
Make sure when you are creating your flat-file IF you have text (varchar) value in any of your columns, DO NOT select your file to be comma "," delimited. Instead, select vertical line "|" or something that you are SURE it can't be in those values. the comma is supper common to have in nvarchar filed.
I have this issue and none of the recommendations from other answers helped me! I hope this saves someone some times and it took me hours to figure it out!!!
Solution 3:[3]
None of these other ones worked for me, however this did:
When you import a flat file, SSMS gives you a brief summary of the data types within each column. Whenever you see a nvarchar that's in an int or double column, change it to int or double. And change all nvarchars to nvarchar(max). This worked for me.
Solution 4:[4]
I've been working with csv data for a long time. I encountered the similar problems when I first started this job, however as a novice, I couldn't obtain a precise fault from the exceptions.
Here are a few things you should look at before importing anything.
- Your csv file must not be opened in any software, such as Excel.
- Your csv file cells should not include comma or quotation symbols.
- There are no unnecessary blanks at the end of your data.
- There is no usage of a reserved term as data. In Excel, open yourfile and save it as a new file.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Kevin Nelson |
| Solution 2 | Reza Shek |
| Solution 3 | Arnav Sharma |
| Solution 4 | Wesley-Sinde |
