2013-03-15 119 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 
相关问题