Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 2005 在SQL Server 2005中部署为作业时,包不工作_Sql Server 2005_Ssis - Fatal编程技术网

Sql server 2005 在SQL Server 2005中部署为作业时,包不工作

Sql server 2005 在SQL Server 2005中部署为作业时,包不工作,sql-server-2005,ssis,Sql Server 2005,Ssis,我开发了一个ssis包,将结果存储在path中的excel工作表中 E:\output\report\Account_28 Mar 2012.xls 现在,我再次从上面的路径打开文件,并在指定的单元格中写入少量内容,然后将其保存回去。如果在我的解决方案vs 2008中,我已将此包部署在服务器it self中,则此功能可以正常工作,如果在我的解决方案中运行,则不会出现任何问题。一切正常 但是,如果我从解决方案中获取包和配置,并将其作为作业部署在服务器中并运行,则会出现此错误 Microsoft

我开发了一个ssis包,将结果存储在path中的excel工作表中

E:\output\report\Account_28 Mar 2012.xls
现在,我再次从上面的路径打开文件,并在指定的单元格中写入少量内容,然后将其保存回去。如果在我的解决方案vs 2008中,我已将此包部署在服务器it self中,则此功能可以正常工作,如果在我的解决方案中运行,则不会出现任何问题。一切正常

但是,如果我从解决方案中获取包和配置,并将其作为作业部署在服务器中并运行,则会出现此错误

Microsoft Excel无法访问该文件 E:\output\report\ExpiredAccount\u 2012年3月28日.xls。有几个 可能的原因:?文件名或路径不存在?这个 文件正在被另一个程序使用?您正在尝试的工作簿 “保存”与当前打开的工作簿同名

我不明白在这里作为作业运行时为什么失败?

环境:SQL Server Business Intelligence Development Studio 2008、SQL Server 2005、Windows Server 2008

错误

:您可能无权访问此信息。这个错误 发生加密错误时发生。验证是否存在正确的 钥匙是可用的。结束错误:2012-03-28 10:39:45.49代码: 0x00000001来源:更新文件说明的内容: System.Reflection.TargetInvocationException:异常已被删除 由调用的目标抛出。--> System.Runtime.InteropServices.COMException(0x800A03EC):Microsoft Excel无法访问文件“E:\output\report\Account\u 2012年3月28日.xls” 2012年3月。有几个可能的原因:?文件名 或路径不存在?另一个程序正在使用该文件。 ? 您试图保存的工作簿与文件名相同 当前打开的工作簿。在 ST_889a4dfd8e9647039213f39fd4c966ab.csproj.ScriptMain.Main()--- 内部异常堆栈跟踪的结束---at System.RuntimeMethodHandle.\u InvokeMethodFast(对象目标,对象[]) 参数,SignatureStruct&sig,MethodAttributes,MethodAttributes,
RuntimeTypeHandle类型所有者)位于 System.RuntimeMethodHandle.InvokeMethodFast(对象目标,对象[]) 参数、签名sig、MethodAttributes、MethodAttributes、, RuntimeTypeHandle类型所有者)位于 System.Reflection.RuntimeMethodInfo.Invoke(对象obj,BindingFlags invokeAttr,绑定器绑定器,对象[]参数,CultureInfo区域性, 布尔skipVisibilityChecks)在 System.Reflection.RuntimeMethodInfo.Invoke(对象obj,BindingFlags invokeAttr,Binder Binder,对象[]参数,CultureInfo区域性)
在System.RuntimeType.InvokeMember处(字符串名称,BindingFlags bindingFlags、Binder Binder、对象目标、对象[]提供的参数,
ParameterModifier[]修饰符,CultureInfo区域性,字符串[] 在System.Type.InvokeMember(字符串名称, BindingFlags invokeAttr、绑定器绑定器、对象目标、对象[]参数、, 文化资讯(文化)网址 Microsoft.SqlServer.Dts.Tasks.ScriptTask.vstatasksscriptingEngine.ExecuteScript() 结束错误DTExec:包执行返回DTSER_失败(1)。
开始时间:10:39:34结束时间:10:39:45经过时间:10.53秒。这个 包执行失败。步骤失败了

请参阅我用于打开Excel文件并将其保存回的代码

public void Main()
{
    try
    {
        string StartDate = string.Empty;
        string EndDate = string.Empty;
        string Reportname = "Employee list"
        string Countryname = "India"
        string Filename = Dts.Variables["User::FileName"].Value.ToString() + ".xls";
        string CurrentDate = Dts.Variables["User::CurrentDate"].Value.ToString();
        string strStarDate = Dts.Variables["User::StartDateTime"].Value.ToString();
        string strEndDate = Dts.Variables["User::EndDateTime"].Value.ToString();

        Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
        Microsoft.Office.Interop.Excel.Workbook wb = app.Workbooks.Open(Filename, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
        Type.Missing, Type.Missing, Type.Missing, Type.Missing,
        Type.Missing, Type.Missing, Type.Missing, Type.Missing,
        Type.Missing, Type.Missing);

        Worksheet sheet = (Worksheet)wb.Sheets["Accounts"];
        Range excelRange = sheet.UsedRange;
        Range rng1 = sheet.get_Range("B1", "C1");
        sheet.get_Range("$B1", "$C1").HorizontalAlignment = XlHAlign.xlHAlignLeft;
        sheet.get_Range(rng1.Cells[1, 1], rng1.Cells[1, 2]).Merge(Type.Missing);
        rng1.Value2 = Countryname;

        Range rng2 = sheet.get_Range("B2", "B2");
        sheet.get_Range("$B2", "$C2").HorizontalAlignment = XlHAlign.xlHAlignLeft;

        sheet.get_Range(rng2.Cells[1, 1], rng2.Cells[1, 2]).Merge(Type.Missing);
        rng2.Value2 = Reportname;
        sheet.get_Range("B1", "B1").Font.Bold = true;
        sheet.get_Range("B1", "B1").Font.Size = 14;
        sheet.get_Range("B2", "B2").Font.Bold = true;
        sheet.get_Range("B2", "B2").Font.Size = 14;
        Range rng3 = sheet.get_Range("A3", "A3");
        sheet.get_Range("$A3", "$B3").HorizontalAlignment = XlHAlign.xlHAlignLeft;
        sheet.get_Range(rng3.Cells[1, 1], rng3.Cells[1, 2]).Merge(Type.Missing);
        rng3.Value2 = "TimeFrame  : " + strStarDate + " " + strEndDate;
        Range rng5 = sheet.get_Range("C3", "C3");
        rng5.Value2 = "Report Run Date : " + "  " + CurrentDate; ;
        sheet.get_Range("A4", "A4").Font.Bold = true;
        sheet.get_Range("A4", "A4").Font.Size = 11;
        //  sheet.get_Range("B3", "B3").ColumnWidth = 56;
        sheet.get_Range("A4", "A4").Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red);
        //Color.Violet.ToArgb(); 

        sheet.get_Range("B4", "B4").Font.Bold = true;
        sheet.get_Range("B4", "B4").Font.Size = 11;
        sheet.get_Range("B4", "B4").Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red);

        sheet.get_Range("C4", "C4").Font.Bold = true;
        sheet.get_Range("C4", "C4").Font.Size = 11;
        sheet.get_Range("C4", "C4").Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red);

        sheet.get_Range("D4", "D4").Font.Bold = true;
        sheet.get_Range("D4", "D4").Font.Size = 11;
        sheet.get_Range("D4", "D4").Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red);

        wb.RefreshAll();
        wb.Save();
        app.Workbooks.Close();
        app.Quit();
    }

    catch (Exception ex)
    {
        throw ex;
    }
}
(由OP在问题编辑中回答。转换为社区wiki答案。请参阅)

OP写道:

我是怎么解决的

在<代码>组件服务>计算机>我的计算机>DCOM配置+Microsoft Excel应用程序>属性>标识选项卡>下,选择交互式用户>确定

然后在代码中,我做了这个更改,以显式关闭打开的文件
app.Workbooks.close()


您尝试运行此操作的服务器上是否安装了Excel??该服务器是否有驱动器/目录
E:\output\report
??运行此程序包的用户是否拥有该目录的权限(如果存在)??请在上面找到我如何解决访问excel的权限问题的答案