【问题标题】:Importing data from table to excel file Errors将数据从表导入excel文件错误
【发布时间】:2024-01-23 22:31:01
【问题描述】:

我正在将数据传输到格式化的 excel 表中。当我尝试执行数据流任务时,我在数据流任务中的目标是 excel,我遇到了以下错误,我试图将设置 64 位更改为 false。 有人可以帮忙解决我哪里出错了。

    [Excel Destination [301]] Error: SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80004005.
[Excel Destination [301]] Error: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR.  The "input "Excel Destination Input" (312)"
 failed because error code 0xC020907B occurred, and the error row disposition on "input "Excel Destination Input" (312)" 
 specifies failure on error. An error occurred on the specified object of the specified component.  There may be error messages
  posted before this with more information about the failure.
[SSIS.Pipeline] Error: SSIS Error Code DTS_E_PROCESSINPUTFAILED.  The ProcessInput method on component "Excel Destination" 
(301) failed with error code 0xC0209029 while processing input "Excel Destination Input" (312). The identified component returned 
an error from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running. 
 There may be error messages posted before this with more information about the failure.

【问题讨论】:

  • 您确定来自 Excel 的数据类型与 SSIS 期望的相同吗?
  • 源是 OLE 提供者吗?

标签: sql-server excel sql-server-2008-r2 ssis


【解决方案1】:

试试这个

在DataTable中获取你的数据然后使用这个函数

 public void ExportToExcel_AsXlsFile(DataTable dt, string file_name)
        {
            var grid = new GridView();
            grid.DataSource = dt;
            grid.DataBind();
            Response.ClearContent();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", "attachment; filename='" + file_name + "'.xls");
            Response.ContentType = "application/ms-excel";
            Response.Charset = "";
            StringWriter sw = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);
            grid.RenderControl(htw);
            Response.Output.Write(sw.ToString());
            Response.Flush();
            Response.End();
        }

【讨论】:

    【解决方案2】:

    错误原因:

    当您在本地计算机上创建包并在其中创建连接时,您可以选择保存该连接的密码。但是,默认情况下,它会加密此密码,因此只有在您使用相同帐户在同一台​​机器上运行程序包时才能解密。仅当连接管理器使用 SQL 身份验证或连接到不支持 Windows 集成身份验证的数据库(例如 Oracle)时,这才有效。 因此,在上述场景中,如果将包部署到远程 Sql Server,则会失败并显示“登录失败..”错误,因为它无法解密密码。 (注:如果部署在本地Sql Server中运行良好)

    分辨率: 要解决此问题,您应该选择以下三个选项之一:

    1. 将包中的所有连接管理器更改为使用 Windows 身份验证。 注意:在与不支持 Windows 身份验证(如 Oracle)的第三方数据源通信时,这不是一个选项。

    2. 使用“EncryptSensitiveWithPassword”或“EncryptAllWithPassword”加密包,并在每次用户想要编辑/操作包时提供包密码。

    3. 创建一个配置文件以在包运行时提供连接信息。

    参考链接: http://technet.microsoft.com/en-us/library/ms140213.aspx**

    【讨论】: