我必须将Excel模板复制到另一个文件夹才能导入数据。以下是我使用两个SQL语句:无法使用SQL Server 2008 R2中的OPENROWSET导入到Excel
insert into
OPENROWSET('Microsoft.ACE.OLEDB.12.0'
, 'Excel 12.0;Database=C:\inetpub\wwwroot\app_data\tmp\myExport130301172218.xls;'
, 'SELECT * FROM [Sheet1$]')
SELECT * FROM vw_shrub
如果我单独执行上面的SQL语句,它们工作得很好:
语句1:
exec xp_cmdshell 'copy C:\inetpub\wwwroot\app_data\export_templates\myExport.xlsx C:\inetpub\wwwroot\app_data\tmp\myExport130301172218.xls'
声明2。但是,如果我一起执行它们,它提出了以下错误:
OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" returned message "The Microsoft Access database engine could not find the object 'Sheet1$'. Make sure the object exists and that you spell its name and the path name correctly. If 'Sheet1$' is not a local object, check your network connection or contact the server administrator.".
Msg 7350, Level 16, State 2, Line 2
Cannot get the column information from OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)".
的问题是我想从我作为单一的请求的应用程序通过他们俩。因此,我必须一起执行它们。我发现我可以在Management Studio中一起执行它们,如果我在它们之间添加GO。但是当我通过我的应用程序的请求时,我无法使用GO。
为什么复制中的路径与OPENROWSET – 2013-03-02 02:13:24
中的路径不同我很抱歉Speot。当我在我的问题中写样本时,这是一个错误。但问题仍然存在。我更新了这个问题。谢谢。 – Fred 2013-03-02 09:12:49
为什么不创建存储过程,而是从您的应用程序调用该过程 – Raymund 2013-03-04 20:44:25