Dynamically assign filename to excel connection string

前端 未结 3 2164
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-27 21:24

This is my very first time playing with SSIS in SQL Server 2012. I can successfully read an excel file and load its content to a table in SQL server 2012. The task is a simp

相关标签:
3条回答
  • 2020-11-27 21:55

    We can define our connection string like below in Expression:

    Provider=Microsoft.ACE.OLEDB.12.0;
    
    Data Source=" + @[User::InputFolder] + "\\"+ @[User::FileName] +";
    
    Extended Properties=\"EXCEL 12.0 XML;HDR=YES\";
    
    0 讨论(0)
  • 2020-11-27 22:00

    I had a heck of a time trying to get this to work, even after following all the instructions, so I just kept it with a static excel name and added a “File System Task” to copy the file and create a new file with whatever name I need.

    0 讨论(0)
  • 2020-11-27 22:13

    Option A

    The ConnectionString property for an Excel Connection Manager is not where I go to manipulate the current file, which is contrast to an ordinary Flat File Connection Manager.

    Instead, put an expression on the Excel Connection Manager's ExcelFilePath property.

    enter image description here

    In theory, there should be no difference between ConnectionString and ExcelFilePath except that you will have more "stuff" to build out to get the connection string just right.

    Also, be sure you're executing the package in 32 bit mode.

    Option B

    An alternative that you might be running into is that the design-time value for the Connection String isn't valid once it's running. When the package begins, it verifies that all of the expected resources are available and if they aren't, it fails fast rather than dieing mid load. You can delay this validation until such time as SSIS has to actually access the resource and you do this by setting the DelayValidation property to True. This property exists on everything in SSIS but I would start with setting it on the Excel Connection Manager first. If that still throws the Package Validation Error, try setting the Data Flow's delay validation to true as well.

    0 讨论(0)
提交回复
热议问题