Ever wanted to get a bunch of pivot table data on excel files refreshed without the need of opening the file at all?
Here's a solution,
download the zip and extract. To use, just create a batch file and execute the .exe file on command line.
http://search.cpan.org/~ctbrown/Win32-Excel-Refresh-0.02/Refresh.pm
Monday, January 14, 2013
Import Excel into SQL 2008 64 bit
Last couple days, I was working on a solution to import some excel file into SQL and then generate report from the server.
There're a lot of ways to import an excel file, I tried a few approaches, unfortunately due to lack of permission to muck around with server settings in the company, I was unable to proceed with most of these approaches.
Approach 1 : (ISSUE: 32 bit office installed, 64bit SQL installed)
I did run step 2&3 on my local machine (XP sp3, 32bit SQL 2008 R2), work like a charm.
Possible issues:
you may come across:
This will fix it :
Also this error is common:
Fixes:
-------------------------------SEPERATOR ------------------------------------------------------------
Approach 2: LINKED Server
Same issue with the first approach, 32 bit office and 64 bit SQL. on all 32 bit servers, everything goes smoothly, where as 64 bit SQL will have errors and not be able to proceed.
There're a lot of ways to import an excel file, I tried a few approaches, unfortunately due to lack of permission to muck around with server settings in the company, I was unable to proceed with most of these approaches.
Approach 1 : (ISSUE: 32 bit office installed, 64bit SQL installed)
Step 1. Install 64-bit Microsoft.ACE.OLEDB.12.0 driver (Failed on this one, Don't have server admin rights to install 64 bit version drivers.)
Step 2. Configure ACE OLE DB properties
EXEC sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'AllowInProcess', 1 GO EXEC sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'DynamicParameters', 1 GO
Step 3. Configure linked server using Microsoft.ACE.OLEDB.12.0 provider
SELECT * INTO #ExcelTemp FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0','Excel 12.0;Database=V:\database\Export\Service KPI Report 2013.xls','select * from [2013$]')
I did run step 2&3 on my local machine (XP sp3, 32bit SQL 2008 R2), work like a charm.
Possible issues:
you may come across:
Msg 15281, Level 16, State 1, Line 1
SQL Server blocked access to STATEMENT 'OpenRowset/OpenDatasource' of component 'Ad Hoc Distributed Queries' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Ad Hoc Distributed Queries' by using sp_configure. For more information about enabling 'Ad Hoc Distributed Queries', see "Surface Area Configuration" in SQL Server Books Online.
This will fix it :
sp_configure 'show advanced options', 1;
RECONFIGURE;
GO
sp_configure 'Ad Hoc Distributed Queries', 1;
RECONFIGURE;
GO
Also this error is common:
Msg 7399, Level 16, State 1, Line 1The OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" reported an error. Access denied.Msg 7350, Level 16, State 2, Line 1Cannot get the column information from OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)".
Fixes:
USE [master]GOEXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'AllowInProcess', 1GOEXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'DynamicParameters', 1GOEXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'NestedQueries', 1GOEXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'NonTransactedUpdates', 1GO
-------------------------------SEPERATOR ------------------------------------------------------------
Approach 2: LINKED Server
Same issue with the first approach, 32 bit office and 64 bit SQL. on all 32 bit servers, everything goes smoothly, where as 64 bit SQL will have errors and not be able to proceed.
EXEC sp_addlinkedserver @server = 'ExcelServer', @srvproduct = 'Excel', @provider = 'Microsoft.ACE.OLEDB.12.0', @datasrc = 'C:\Test\test.xlsx', @provstr = 'Excel 12.0;IMEX=1;HDR=YES;'
-------------------------------SEPERATOR ------------------------------------------------------------
Approach 3: SSIS
Easy enough, end up doing this.
Subscribe to:
Posts (Atom)