0

我的 SSIS 包中有一个 C# 脚本任务,我可以在我的计算机上毫无问题地运行它。但是当我将它部署在我的服务器上并从 sql 作业执行包时,我得到一个错误。使用 try/catch 子句,我在 txt 文件中得到了这个:

Message :Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).<br/>
StackTrace :   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at System.Activator.CreateInstance(Type type)
   at ST_86c290165eda4c9a962b68fdf181801f.ScriptMain.Main()

有人可以解释一下问题是什么吗?

服务器上安装了驱动程序 ACE.OLEDB 12.0 和 16.0 (SQL server 2014 SP2 CU11)

如何在不使用 interop 的情况下更改脚本以更改字体?

这是我的 C# 脚本

#region Namespaces
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.IO;
using System.Runtime.InteropServices;
using Excel = Microsoft.Office.Interop.Excel;
#endregion

namespace ST_86c290165eda4c9a962b68fdf181801f
{
    [Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
    public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
    {   
        public void Main()
        {
                String FilePath = Dts.Variables["User::excelPath"].Value.ToString();
                Excel.Application excelApp = new Excel.Application();
                Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(FilePath);
                Excel.Sheets excelSheets = excelWorkbook.Worksheets;

                Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelSheets.get_Item(1);
                Excel.Range excelCell = (Excel.Range)excelWorksheet.Cells;
                excelCell.Font.Name = "Arial";
                excelWorkbook.Save();
                excelWorkbook.Close(true);
                excelApp.Quit();
                System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
        Dts.TaskResult = (int)ScriptResults.Success;
        }

        #region ScriptResults declaration
        enum ScriptResults
        {
            Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
            Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
        };
        #endregion

    }
}
4

1 回答 1

0

CLSID {00024500-0000-0000-C000-000000000046} 指的是 Microsoft.Office.Interop.Excel。

我建议您需要在服务器上安装 Excel。我不知道是否有特定的“互操作”安装,但它可能在 Excel 的自定义设置中可用。

于 2018-05-22T11:33:59.117 回答