views:

2467

answers:

4

What's the best/smoothest solution to import an Excel-file to SQL Server, on a 64 bit Windows system?

What I'm specifically after is to import an Excel 97-2003 file, to a SQL 2005 database, from an ASP.NET/C# page. The import data will demand users to use a "template", so the data looks the same every time.

Previously the system has used Microsoft Jet OleDb 4.0 for this kind of import, but now it has moved to a 64 bit environment. I know Jet can run on 64 bit, if IIS is run in 32 bit mode, but that is in my opinion not an option.

So, what are the 64 bit alternatives here?

A: 

You could upload the file and save it in a specific folder and then have a Windows service or other process that runs in 32-bit and in the background. This background process monitors the upload folder and imports newly Excel files into SQL Server.

The disadvantage is that you don't have direct reponse to the user.

Michael
A: 

I would do this by reading the excel file into a DataTable object and then using SqlBulkCopy to store the information. This would be fast and relatively simple to code.

Rune Grimstad
How would you read it into a DataTable object?
Bravax
There are lots of components that allow you to read excel files for .Net. One is the open source myXls component: https://sourceforge.net/projects/myxls/ but there are several others as well.
Rune Grimstad
Thanks for you suggestion. The problem is however that most Excel file readers - MyXLS being one of them, as far as I can tell - still use the Jet OleDb, which doesn't really solve the problem.
Marcus L
Actually it doesn't use Jet OleDb. It will read the Excel Ole2 container and extract the excel data. Are you sure about this? I don't think I have seen any excel components that use OleDb.
Rune Grimstad
I'm not 100% sure, as I've not tested it in the code yet, I just found references to the OleDb in the source code. I'll hopefully have the time to do a propper test next week - by which time the problem might be out of my hands. I'll let you know the result when/if I try it.
Marcus L
As author of MyXls I can tell you it does not utilize OLEDB in any way. However, a few of it's unit tests do utilize OLEDB to independently verify MyXls's read/write logic against/across the entire Northwind DB dataset. This may be the OLEDB reference you speak of if you did a simple search for OLEDB across the source files. This reference is only in the MyXls.Tests assembly, and so is not a part of or referenced by the MyXls assembly itself.Hope this helps anyone reading this later!
Tim Erickson
+2  A: 

You should use Integration Services. Create an Integration Services package that load the Excel file (relatively easy thing to do; you can even use the Import and Export wizard), and then call the package from asp.net

santiiiii
I got a bunch of other bugs to solve, and this one got dumped on another guy. Not sure how he'll decide to solve it, but your answer was very creative, so you get the answer-tag. :)
Marcus L
A: 

Another way to read Excel into an ADO.NET DataTable:

http://www.aspspider.com/resources/Resource510.aspx

Although I would also recommend just using an SSIS package to do the work.

kthejoker
Does this needs to have Excel installed in the server?
Sebastian