How to read more than 400 meg excel in sql - c#

How can I import that Excel file into SQL Server? I have more than 400 meg Excel file which has two sheets.
I want to know that if is there any way by which can I read it in chunks/parse it to csv and then import. I need to know if it can be done without using oledb or openxml or any other kind of automation tools.
I have checked the options with openxml and tried to send it to SQL Server but not getting enough luck, I have tried oledb but it seems like that oledb is having its own limitations.
Thanks

If you have sql server integration services or data tools installed you can use the Sql Server Wizard to "Import and Export Data". There you choose "Excel File" as Source, your Database as Destination and then you can define table and column mappings including the necessary data conversions. You can also define pre- and post-import sql commands (like drop and (re)create the table that you want to import the data into... or simply empty the table).
As soon as you have the whole import defined you can save a so-called SSIS (Sql Server Integration Service) - Package either into your database or into a file nested in your solution. That *.dtsx file can be opened with the "Sql Server Integration Services Package
Execution Utility" to automatically run the import.
So you could run the import at some time in your build-process or even start it in a background process. Just make sure you place your excel file where you've defined the source for the import to be.
If you have Visual Studio 12 and up, Sql Server Data Tools should be automatically installed. With those in place you can open up the *.dtsx files at any time in your Visual Studio and modify the import behaviour. I've only recently copied such a .dtsx-file because i need to import an excel file into 4 different staging databases, so for each database i just modified the corresponding copy of the .dtsx-file's database-connection-credentials.

I would suggest taking a look at python + pandas - pandas has a method for reading from excel into pandas data frames, read_exel(), and to write to your sql database, to_sql().

Related

How to import data from Excel to C# Service based database?

Im using C# and Service based database and I need to import some data from Excel to my database ..How could I possibly do this?? Please help. Thanks a lot.
You can open the excel file with the Excel database driver and read it like any other data source, however this means you need the driver, which isn't installed by default.
Download
HowTo
However if the sheet only contains data and doesn't need any calculations, you can unzip the XLSX file, and find sheet1.xml (or whatever it's called in your file), open it in your app like any other XML file and import the data.
This is likely to be a much better long term solution, since MS has been trying to kill off the Access database driver for ages.
Also, it's been a while, but I don't believe MS recommends using the MSDE from within a service.
I would recommend you to use OfficeOpenXml.Core.ExcelPackage or EPPlus to read/write excel files. Bellow is some links to reference
https://www.nuget.org/packages/OfficeOpenXml.Core.ExcelPackage/
https://github.com/JanKallman/EPPlus
https://www.c-sharpcorner.com/article/import-and-export-data-using-epplus-core/
https://tedgustaf.com/blog/2012/create-excel-20072010-spreadsheets-with-c-and-epplus/
http://www.talkingdotnet.com/import-export-xlsx-asp-net-core/
https://toidicodedao.com/2015/11/24/series-c-hay-ho-epplus-thu-vien-excel-ba-dao-phan-1/
http://www.zachhunter.com/2015/11/xlsx-template-with-epplus-and-web-api-save-as-xlsx-or-pdf/

Is there a way to import data from an excel sheet into a SQL Server database?

Is there a way to import data from an excel sheet into a database on SQL Server without using the bulk method? Keeping in mind that I'm creating a web application where the user uploads an excel file to the page and it proceeds to import it into an existing database.
The bulk method works using OleDbDataReader, except it copies the excel sheet and pastes it onto the database without considering the column names compatibility. Am I missing something?
If you are working through SSMS, use the SQL Import Export Wizard. There's enough documentation on MSDN
From code you can use the SqlBulkCopy class for importing into SQL databases. If you are importing bulk records into Oracle you can use ODP.net OracleBulkCopy. Oracle bulk copying is only supported right now through the full ODP.net provider. Managed ODP.net does not support bulk operations.
To read the Excel file you can use any number of libraries.
LinqToExcel,
OleDb,
closedxml
Take a look at the DocumentFormat.OpenXml.Spreadsheet namespace: MSDN Link
It will let you look at the different parts of the spreadsheet as it is stored in OpenXML.
You can use format file along with bulk insert. The format file maps between table columns and the fields in the file.
Refer :
https://learn.microsoft.com/en-us/sql/relational-databases/import-export/use-a-format-file-to-bulk-import-data-sql-server

Table format output from SSIS to C#

I'm able to call SSIS Package and get the result of package execution status from C# application. The problem is I want to retrieve the a tabular data which is output from SSIS package to C# application.
I aware of the options of staging the resultant data to a SQL Server table / to a CSV file and then let C# application read the data. I'm looking for directly reading the data output from SSIS to C#. I'm not sure if this is possible. Please could you share your thoughts on how to achieve this.
Limitations : I can't read the data of the database from C#. It has to be routed through SSIS after a series of transformations.
This isn't possible, SSIS won't output that data for you. As you've suggested, you'll need SSIS to write the data to a destination (SQL Server, flat file, etc.) that your application can then read in as another step.

Importing huge data from text file to sql using c# winforms

I am wanting to add the ability to import massive CSV files into a table in the database. I've built an SSIS package that does this, but I just wanted to make sure that this was the correct way of doing it.
The text files are millions of rows with 50 columns. They don't open in notepad or notepad++ a lot of times. The SSIS package handles them with no problem and gets everything imported. Is SSIS the right way to deal with this? I just need to pass the file location parameter to the job and execute it right? Is there an easier way that I am overlooking?
The text files are millions of rows with 50 columns
Small. Why an SSIS package?
They don't open in notepad or notepad++
because both OPEN them - there is no need to open them and load them all into memory, a proper application can read them line by line.
Is SSIS the right way to deal with this?
No. SImply because the title is: Importing huge data from text file to sql using c# winforms
As Winforms can do that effectively - I am inserting around 100.000 rows into a database - in C# with quit eeasy coding (except some pages and a day to get sqlbulkcopy to work properly) and you say nothing about any transformations, SSIS just is another not needed technology AND makes things complicated (as in: more to install, or hav a packag on the server but then find a location for the file that the server can reach etc.
I am all for SSIS and if you have a larger SSIS infrastructure or do a lot of processing etc. and it makes architectural sense in a larger context - yes. But as the question stands, without additional reasons - absolutely not.
Heck, there is a good chance you can load the whole thing in one command into SQL server as SQL Server has some CSV processing capabilities:
http://blog.sqlauthority.com/2008/02/06/sql-server-import-csv-file-into-sql-server-using-bulk-insert-load-comma-delimited-file-into-sql-server/

How to upload data from Excel file to Sql Server using BizTalk

I wanted to upload data from an Excel file (which will be located at some specified folder) to SQL Server using BizTalk.
I am using Visual Studio 2010,.NET V4 and SQL Server 2008.
Can anyone please provide me detailed steps of how to achieve this or any existing discussion/forum link for the same.
Thanks,
Mayur Jadhav
Mayur, Excel sheets are basically binary files, you need a custom pipeline component for processing this excel file. I'm pasting a link here that will help you out to carry out the desired task.
There is another article uploaded here in the code project that aims to discuss how to read an Excel file from a pipeline in BizTalk. A custom pipeline need to be developed to read Excel files. Excel file will be read by taking the file adapter and the pipeline will process it. A custom pipeline component is nothing more than a simple .NET DLL that implements a class with some predefined interfaces. This interface represents the layer between a .NET program and the BizTalk Server.
Hope that it helps!
first you need to create flat file schema
how to create flat file schema in biztalk
than you need to insert the data in to the DB i would use a store prudence that will insert the data into the db and than use the LOB adapter in order to cunsume it inside biztalk orchestration LOB Adapter
There are a couple of options to process Excel files..
If you can control then save the Excel Files as XML and process them, otherwise looks for excel adapter for Biztalk. For example
You will then just have to work with mappings and port files. This should help you.

Categories

Resources