如何在SSIS中运行Excel宏时修复System.NullReferenceException错误?

时间:2013-02-21 11:33:57

标签: ssis

我已经在SSIS 2008上使用运行excel宏的vb脚本设置了一个包。它适用于商业智能开发工作室(BIDS) 2008但仍然出现以下错误:

Error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object. 
at ST_e916156b0e6449b58e21905bd635ecf0.vbproj.ScriptMain.Main() 
--- End of inner exception stack trace --- 
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) 
at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) 
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) 
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) 
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams) 
at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, CultureInfo culture) 
at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript() 

此外,当我使用SQL代理运行包时,作业成功但宏未执行,我收到以下错误:

Executed as user: 'myusername'. 
Code: 0xFFFFFFFF 
Source: Run macro script excel macro Description: Microsoft Excel cannot access the file 'book1.XLS'. 
There are several possible reasons: 
? The file name or path does not exist. 
? The file is being used by another program. 
? The workbook you are trying to save has the same name as a currently open workbook. 
End Error 
DTExec: The package execution returned DTSER_SUCCESS (0). 
Started: 11:18:15 Finished: 11:18:19 
Elapsed: 3.775 seconds. 
The package executed successfully. The step succeeded. 

但是,我可以完全访问本地服务器和网络,并且我尝试在32位和64位上运行,但没有成功。

我如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

你可以尝试的事情:

根据我的个人经验,使用SSIS时Excel总是很棘手。正如您从错误消息中看到的那样,请确认您可以排除有关该问题的以下信息。

  • 检查运行SQL Server代理服务的用户帐户。您可以导航到 Windows Start \ Control Panel \ Administrative Tools \ { {1}} 的。寻找名为 Services

  • 的服务
  • 确保该帐户可以访问存储Excel文件的文件夹。

  • 确认您没有打开Excel文件。

  • SQL Server代理作业上,单击执行包的步骤。如果您在 SQL Server Agent (<your instance name>) 类型下运行该软件包,请确保在 {{1}上选中 SQL Server Integration Services Package 框} 标签。

  • 您也可以手动双击包文件(.dtsx)。这将带来执行包的 User 32 bit runtime 实用程序。如果使用配置文件,请在“配置”选项卡上附加配置文件。运行包。如果它在您的凭据下的 Execution options 实用程序中运行,但在SQL Server代理下运行,我通常会发现这是相关的权限问题。