Errors while importing data from flat file to database table - sql-server

I got these error message while importing data from flat file to sql server table using import export wizard in ssms :-
The mapping window :-
I know there is a issue regarding datatype mismatch,how should I overcome that?

As per error, it indicate that your flat file is not in proper format, in file some of the row has messing (, or tab) delimiter.

Related

Cannot import long text from Excel to SQL Server using SSIS

Environment:
Microsoft® Excel® for Microsoft 365 MSO (Version 2112 Build 16.0.14729.20254) 64-bit
Microsoft SQL Server 2019 (RTM-CU14) (KB5007182) - 15.0.4188.2 (X64)
Microsoft Visual Studio 2019
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\ClickToRun\REGISTRY\MACHINE\Software\Microsoft\Office\16.0\Access Connectivity Engine\Engines\Excel\TypeGuessRows set to 0
In Excel I formated the cell as "Text" and I also filled up the 2nd and 3rd rows with some super-long dummy text... (1st row is title row)
When I go to Excel Source/Advanced editor, I can set the Output to Unicode text stream [DT_NTEXT] or anything else but the External column cannot be changed to something else than Unicode string [DT_WSTR] (255 characters) despite the setting in registry that normally should allow it and despite having super-long strings in first two rows (other than the 1st row which holds the field names)
Then of course when I try to execute the SSIS task it throws a normal truncation error.
Question: What I am doing wrong or what else should be done here to actually be able to import the data? By the way, this is supposed to be automated at some point.
Since an Excel workbook is not a database, the OLE DB provider tries to detect the most relevant metadata from the Excel worksheet and read it as tabular data, which is mostly inaccurate when handling medium and large Excel files. After spending years on creating SSIS packages, I will convert the Excel file to a CSV file and import it using a Flat File Connection Manager instead. Or I will use a C# script to import the data.
I. Converting Excel to CSV
You can automate the process of converting Excel to CSV using a C# script:
Converting XLSX file using to a CSV file
Convert .xlsx & .xls to .csv
How to Convert Excel to CSV using Interop
After converting the Excel file to a CSV file, you can dynamically import it using a Flat File Connection Manager:
Dynamic Flat File Connections in SQL Server Integration Services
II. Using a C# script
It is good to check the following class, which is a part of the SchemaMapper project:
SchemaMapper - MsExcelImport.cs
Besides, a step-by-step guide on how to use this library can be found in the following link:
Import data from multiple files into one SQL table step by step guide
III. Editing the Excel connection string
If you don't have the choice to convert Excel to flat files, then you can force the Excel connection manager to ignore headers from the first row by adding IMEX=1 to tell the OLEDB provider to specify data types from the first row (which is the header - all string most of the time).
To edit the connectionstring property, click on the Excel Connection Manager and press on the F4 key. In the Properties Tab, you can edit the connectionstring property.
SSIS Excel Import Columns with More or Less than 255 Characters
IV. Changing columns length from advanced editor
Try changing the Excel Source column metadata from the advanced editor:
In SSIS excel datasource not taking more characters than 255
Importing Excel using SSIS may cause a headache! You can check the following question:
Workaround for exporting data to Excel with more than 255 columns
Dynamically Creating Excel table through SSIS
SQL Server Import Wizard doesn't support importing from excel sheet with more than 255 columns
Importing Excel Data Seems to Randomly Give Null Values
Failing to read String value from an excel column
Importing Excel Data Seems to Randomly Give Null Values
SSIS - Excel data shows as scientific notations and Null Values

Error while trying to create table in MSSQL using flat-file import

I am trying to import a .csv file to SQL Server Native 11.0 in order to create a table.
However, I am getting the following error:
Warning 0x80070020: Data Flow Task 1: The process cannot access the file
because it is bein gused by another process.
Error 0xc020200e: Data Flow Task 1: Cannot open the datafile
Following the the .csv data:
Need help in figuring out the solution for these errors.
Issue: This was happening because I have opened the .csv file in excel and at the same time I was trying to import it to SQL Server.
Solution: Try closing the file before importing. It should work then, as it worked for me.

Import DBF file into SQL Server : error "The search key was not found in any record"

I'm trying to import an external vendor's ,dbf file into our SQL Server 2016 database for reporting. I've created a linked server and can import from most of the tables except for some which provide the error
The Search key was not found in any record
I'm doing a simple select to test the connection
SELECT * FROM [LINKED_SERVER]...[packet]
If I copy the .DBF file to my computer and use "DBF Viewer 2000" to remove empty records, the select query works fine, so suspect it's something in the file that is corrupted.
I copy the .DBF file to my DB server before I import it. The vendor insists the .DBF file isn't corrupt, so I need to handle this on my side. Is there a way to handle this in SQL? Alternatively, does anyone know of a free command line application that I can use to run a repair and remove empty records?
Thanks
Stephen
The possible cause of this error is space in column names. Carefully check leading space, trailing space and also space inside of the column name.

Import flat file into SQL Server

I'm trying to import a flat file into SQL Server and I'm having some issues. The column delimiter is ;~ and the row delimiter is |~. I'm using the SQL Server Import and Export Wizard but keep getting errors. Have any of you every had a similar issue? I think I'm doing it wrong from the start of the wizard. Can any of you talk me through the steps. Thanks.
Here is the import error:
It's a familiar-sounding problem, but difficult to be sure without a data file to play with - perhaps one of these posts has your answer:
Text was truncated or one or more characters had no match in the target code page including the primary key in an unpivot
Errors in SQL Server while importing CSV file despite varchar(MAX) being used for each column
SQL Server Import wizard fails with incomprehensible message
Thanks to all of you who responded.
My solution was to first create the tables in SQL Server using the varchar(max) data type for each column and then executing a BULK INSERT statement. Definitely not ideal, but the goal was not to create a database but rather delimit the data so I could upload it to an application. Thanks again.

How do I copy a csv file into a mssql database?

I am looking for help to migrate my mysql over to mssql.
I have taken the database from MySQL and created a .csv file.
But from here I get stuck.
I hope you can help me to understand this.
Using Sql Server Import Wizard
1) Open Sql Server Managment Studio
2) Go Import Wizard.
3) Point the Wizard at your file (I would recommend saving the csv to excel tho).
4) Map Columns to appropriate datatypes and lengths.
Open Sql Server Management Studio; connect to your server.
Right click your database in Object Explorer, and go to Tasks -> Import Data...
In the wizard that pops up, choose a Data Source of "Flat File Source", and browse to your csv file for File Name.
For Format, choose "Delimited".
For Text Qualifier, type in one double-quote character: ". This is an important step that will let SQL read in strings properly.
Depending on your file, check or un-check the "Column names in the first data row"
For the most part, this will import your file in. You may need to tweak some of the settings under the Advanced section if your data has text > 50 characters or numeric characters, but the Preview section will show you how the file looks so far.

Resources