2013-04-30 232 views
0

我正在開發一個應用程序,我需要將數據從Excel導入MS SQL Server數據庫。 我的MS SQL Server計算機上,以及我的機器從Excel導入數據到SQL Server數據庫使用Microsoft.ACE.OLEDB.12.0

配置的MS SQL服務器這樣安裝Microsoft Access Database Engine 2010 Redistributable:我使用

USE [master] 
GO 
sp_configure 'show advanced options', 1 
GO 
RECONFIGURE WITH OverRide 
GO 
sp_configure 'Ad Hoc Distributed Queries', 1 
GO 
RECONFIGURE WITH OverRide 
GO 
EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0' , N'AllowInProcess' , 1 
GO 
EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0' , N'DynamicParameters' , 1 
GO 

在我的應用程序:

SELECT * FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0;Database=PathToMyExcelDoc', [Devices$]) 

當應用程序和SQL Server在同一臺機器上時,它工作正常,但是當我在我的機器上運行應用程序並嘗試將數據從Excel導入到遠程SQL Server時,出現以下錯誤:

The OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" reported an error. The provider did not give any information about the error. 
Cannot initialize the data source object of OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)". 

回答

2

我一直面臨同樣的問題,我解決了它首先將excel保存到服務器,然後在OPENROWSET中傳遞該路徑。

+0

所以你的意思是:當我瀏覽Excel文件時,我必須先將它上傳到SQL Server所在的服務器,然後執行導入數據。 如果是,在這種情況下如何將文件上傳到遠程服務器?我正在研究WPF應用程序(C#)。 – Stacked 2013-04-30 09:37:56

+0

是當然..... 其實我仍然在學習WPF與這部分我可能不會很有幫助... – Timon 2013-04-30 09:43:51

+0

謝謝,但我的評論的第二部分(如何上傳文件?)呢? – Stacked 2013-04-30 09:45:43

相關問題