2013-03-15 122 views
1

我使用Excel收集配置數據&,然後將其導入到SQL Server 2012中進行存儲。將Excel 2010導入到SQL Server中

到目前爲止,我一直在使用SQL Server導入&導出嚮導,但不斷手動設置它是一件痛苦的事情。由於我使用的是Express,當然它不允許我保存甚至查看傳輸數據的實際命令。

我試圖建立一個鏈接的服務器,每How to use Excel with SQL Server linked servers and distributed queries,但出現以下錯誤:

The linked server has been created but failed a connection test. Do you want to keep the linked server?

An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)

Cannot initialize the data source object of OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "FLTST".
OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "FLTST" returned message "Unspecified error". (Microsoft SQL Server, Error: 7303)

我想也許Excel版本號是問題,因爲網頁是從2005年的,所以我與嘗試:

  • Excel作爲所示的頁面
  • 的Excel 12.0(Excel 2007中),這是精靈,似乎有什麼使用上的8.0(Excel 2002中)
  • Excel 14.0(Excel 2010)我實際上有

所有這些給了我相同的結果。

接下來,我(與供應商串的不同變化再次)嘗試分佈式查詢截至Import excel file to SQL Server Express所示,

USE ExTest 

SELECT * INTO TstTbl FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0', 
'Excel 14.0;Database=c:\ExTest.xlsm', [Contacts]) 

go 

使我有以下錯誤:

OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)" returned message "Unspecified error".
Msg 7303, Level 16, State 1, Line 3
Cannot initialize the data source object of OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)".

代替去SQL Server &拉數據,我應該留在Excel &推它嗎?

我在做什麼錯?

PS:不要告訴我把它轉換成csv文件!我試圖做更少步驟,而不是更多!

+0

「這是一個痛苦的手動設置它不斷地」。這是因爲你的Excel字段改變了還是因爲你不喜歡通過嚮導?您應該可以保存包並在下次重新運行它....我認爲 - 並非100%確定SQL Express。 – 2013-03-15 05:43:52

+2

在你的情況下,我可能只需編寫一個C#應用程序來讀取Excel並從中獲取所需的數據,然後將這些行插入到SQL Server中。 「Jet OleDB」驅動程序出了名的難以使用 - 尤其是在64位服務器操作系統上 - 所以如果可能的話,我會盡量避免使用這些驅動程序 – 2013-03-15 05:56:42

+0

如果你的excel文件架構沒有改變,只有文件名正在改變,那麼你可以嘗試要設置一個包含動態源代碼的SSIS包來解決您的問題,您不需要每次都通過嚮導,只需在每次更改源時更新SSIS配置即可。 – ljh 2013-03-15 05:58:17

回答

0
  1. 創建SSIS包用Excel數據源的連接管理器,目的是你的SQL Express,OLE DB目標
  2. 當您創建的Excel連接管理器,你可以只使用一個現有的Excel文件
  3. 定義一個用戶變量,如user :: sourceFile,用於輸入excel文件的完整路徑
  4. 創建Excel連接管理器後,右鍵單擊 - > preperties->找到「Expression」,只需將[User :: sourceFile]表達式
  5. 只需從喲創建一個簡單的數據流您的源到目的地
  6. 保存並調試您的SSIS包,確保所有憑證工作和數據都可以流入目標表。注意:不要在你的包保存sensitvie數據與機器密鑰ecrypted
  7. 當你需要加載一個新的文件,使用DTEXEC執行包和覆蓋參數

好運每次

+0

我沒有忘記你,我只是沒有時間與你的解決方案一起努力使它工作:( – 2013-03-18 02:42:10

2

在你的問題中有類似的問題,我已經做了一些研究。我的問題還沒有完全解決,但我想我可以讓你更進一步。雖然問題很老,但也許有人需要幫助。

運行:

SELECT * 
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0 Xml;HDR=YES;Database=P:\Path\File.xlsx','SELECT * FROM [Sheet1$]'); 
GO 

我收到以下錯誤信息:

Msg 15281, Level 16, State 1, Line 19 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', search for 'Ad Hoc Distributed Queries' in SQL Server Books Online.

要解決,我運行以下命令:

sp_configure 'show advanced options', 1 
RECONFIGURE 
GO 
sp_configure 'ad hoc distributed queries', 1 
RECONFIGURE 
GO 

但我得到一個新的錯誤mesasge :

Msg 7302, Level 16, State 1, Line 19 Cannot create an instance of OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)".

爲了糾正我跑:

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 

但我代替得到這個錯誤:

Msg 7438, Level 16, State 1, Line 19 The 32-bit OLE DB provider "Microsoft.ACE.OLEDB.12.0" cannot be loaded in-process on a 64-bit SQL Server.

在我來說,我已經要求IT部門安裝的64位版本練成的服務器和我希望這應該是從Excel導入時的技術問題的結束。

要清理之後,我禁用我剛啓用的設置:

EXEC sp_MSSet_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'AllowInProcess', 0 
GO 

EXEC sp_MSSet_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'DynamicParameters', 0 
GO 

sp_configure 'ad hoc distributed queries', 0 
RECONFIGURE 
GO 

sp_configure 'show advanced options', 0 
RECONFIGURE 
GO 
相關問題