为什么运行SSIS的SQL作业无法将Excel文件移动到SharePoint文件夹?

我已经在SQL Server 2008 R2中创build了一个多步骤的SSIS包,它在集成服务中的DTS包下启动时运行良好,但是在涉及将一个Excel文件复制到SharePoint文件夹的步骤中在SQL Server代理作业中调用时失败在服务器上创build。 在程序包中,Run64bitRuntime设置为False,并且在作业的某个步骤中调用程序包时,会在“执行”选项下选中“使用32位运行时”。 这适用于从位于其他SharePoint文件夹中的Excel文件中读取信息的其他SSIS包。 这里唯一的是我正试图现在复制到SharePoint文件夹在服务器上创build一个Excel文件。 如果不是Excel文件的唯一格式和内容,我将使用SSRS来代替。

这是当我selectSQL Server代理作业的“查看历史logging”时返回的错误消息。

date2013年1月29日下午3时13分47秒日志工作历史(数据拉)

步骤1服务器xxxx-xxx-xx作业名称数据拉步骤名称运行xxxx_Extractxxx持续时间00:16:13 Sql严重性0 Sql消息ID 0运营商通过电子邮件发送操作员networking发送操作员分页尝试0

信息

以用户身份执行:CABLE!svcnvdeautomation。 Microsoft(R)SQL Server执行包实用程序版本10.50.1600.1(32位)版权所有(C)Microsoft Corporation 2010.保留所有权利。
开始:3:13:47 PM错误:2013-01-29 15:30:00.01代码:0x00000001源:创buildExcel文件说明:System.Reflection.TargetInvocationException:exception已被调用的目标引发。 —> System.Runtime.InteropServices.COMException(0x800A03EC):来自HRESULT的exception:0x800A03EC在Microsoft.Office.Interop.Excel.WorkbookClass.SaveAs(Object Filename,Object FileFormat,Object Password,Object WriteResPassword,Object ReadOnlyRecommended,Object CreateBackup ,XlSaveAsAccessMode AccessMode,Object ConflictResolution,Object AddToMru,Object TextCodepage,Object TextVisualLayout,Object Local)在ST_87e8d62a054b4e16b60297154afc19d8.csproj.ScriptMain.Main()—内部exception堆栈跟踪结束—在System.RuntimeMethodHandle._InvokeMethodFast(Object target ,Object []参数,SignatureStruct&sig,MethodAttributes methodAttributes,RuntimeTypeHandle typeOwner)在System.RuntimeMethodHandle.InvokeMethodFast ,BindingFlags invokeAttr,Binder binder,Object []参数,CultureInfo culture,Boolean skipVisibilityChecks)System.Reflection.RuntimeMethodInfo.Invoke(Object obj,BindingFlags invokeAttr,Binder binder,Object []参数,CultureInfo culture)
在System.Type.InvokeMember(String name,BindingFlags invokeAttr,System.RuntimeType.InvokeMember(String name,BindingFlags bindingFlags,Binder binder,Object target,Object [] providedArgs,ParameterModifier [] modifiers,CultureInfo culture,String [] namedParams)在Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()结束错误DTExec:包执行返回DTSER_FAILURE(1)的目标,对象[] args,CultureInfo文化)。 开始时间:3:13:47 PM完成时间:3:30:00 PM已用时间:972.573秒 包执行失败。 该步骤失败。

如果有帮助,下面列出的是用于复制Excel文件的代码。

public void Main() { SharePointListsService.Lists listService = new SharePointListsService.Lists(); listService.Credentials = System.Net.CredentialCache.DefaultCredentials; // Create variable with format of "2012-11-28" string DateTimeNow = DateTime.Now.ToString("yyyy") + "-" + DateTime.Now.ToString("MM") + "-" + DateTime.Now.ToString("dd"); // Check out the file as defined in SharePoint. string fileCheckout = "http://xx.yy.com/Shared%20Documents/Task%20Compliance%20Report.xls"; bool myResults = listService.CheckOutFile(fileCheckout, "true", DateTime.Now.ToString("f")); // Full file name including path and extension // "D:\Work area\Reports\Project.xls" string FullFileName = Dts.Variables["User::ReportsExcelFileName"].Value.ToString(); // File Name without path and extension // "Project" string FileName = GetFileNameWithoutExtFromPath(FullFileName); // Path only // "D:\Work area\Reports\" string Path = GetDirFromPath(FullFileName); // From the source file (FullFileName) assemble the [Path] and [Filename] of new file copy that includes a specific date format attached to new file name. // "D:\Work area\Reports\Project 2012-11-28.xls" File.Copy(FullFileName, (Path + "\\" + FileName + " " + DateTimeNow + ".xls"), true); // Get UNC Folder path // "\\xx.yy.com\Shared Documents\Data Pulls" string UNCFolder = Dts.Variables["UNCFolder"].Value.ToString(); // Get File name as it appears in the Reports folder string ReportsExcelFile = FullFileName; // Copy the Excel file from the Reports directory to the SharePoint UNC folder location File.Copy(ReportsExcelFile, (UNCFolder + "\\" + FileName + ".xls"), true); //Check in //string fileCheckin = Dts.Variables["User::URLFolder"].Value.ToString(); string fileCheckin = "http://xx.yy.com/Shared%20Documents/Task%20Compliance%20Report.xls"; myResults = listService.CheckInFile(fileCheckin, "Completed revision.", "0"); Dts.TaskResult = (int)ScriptResults.Success; } public String GetFileNameWithoutExtFromPath(String path) { try { String filename = path.Substring(path.LastIndexOf("\\") + 1); int pos = filename.LastIndexOf("."); if (pos != -1) return filename.Substring(0, pos); else return filename; } catch (Exception) { // error return ""; } } public String GetDirFromPath(String path) { try { return path.Substring(0, path.LastIndexOf("\\") + 1); } catch (Exception) { // error return ""; } } 

在SQL Serverconfigurationpipe理器下,我已经设置SQL Server代理应用networking访问login,由其他作业调用的其他SSIS包成功应用。 此外,在服务器上的“组件服务”下,我已经进入“我的电脑”,右键单击并select属性,这六个选项卡打开了“我的电脑属性”框。 我select了“COM安全性”选项卡,并为“访问权限”和“启动和激活权限”编​​辑了“编辑限制”。 在每个我添加networking服务。 对于访问权限,我选中了“允许本地访问”和“启动和激活权限”,我select了本地启动和本地激活。

鉴于上述细节,有人可以帮助我确定为什么SSIS包在SQL Server代理下运行时通过Excel文件复制的步骤继续失败?

我假设SQL作业正在运行SQL Server Agent Service Account下的SSIS包,该SQL Server Agent Service Account可能没有权限将文件从一个文件夹位置复制/移动到其他位置。 您需要设置使用域帐户(最好)凭据的代理帐户。 域帐户应具有正确级别的权限以在文件夹之间复制/移动文件。

回答下面的问题,一步一步地介绍如何configuration代理帐户。 它还解释了如何使用代理帐户在SQL作业中执行SSIS包。

如何在我的SQL Server代理作业中创build一个将运行我的SSIS包的步骤?

至less,这是我在文件夹之间移动文件时遇到的类似问题。

希望能引导你find解决问题的办法。

添加C:\Windows\SysWOW64\config\systemprofile\Desktop文件夹为我工作。