Import files into database, variable filenames

  • I would like to develop an SSIS package that inspects a folder and imports the contents of the folder into a database. However, the filename(s) are timestamped, so they vary.

    How can I import these files into the database? It looks like any file-system task in SSIS expects a connection manager where the filename is hardcoded. How can I get around that?

    __________________________________________________________________________________
    SQL Server 2016 Columnstore Index Enhancements - System Views for Disk-Based Tables[/url]
    Persisting SQL Server Index-Usage Statistics with MERGE[/url]
    Turbocharge Your Database Maintenance With Service Broker: Part 2[/url]

  • Depending on your naming convention you ought to be able to use a For Each Loop control and wild card the file specification. Map the result to a variable and then use the variable in whatever dependent task you need it in - within the scope of the Foreach Loop Container of course. For instance if you wanted all the ReportServer log files from the reporting services logfiles directory the file spec might be ReportServer*.log.

    Good luck.

    Eric

  • Using the Foreach Loop container is part of it. In the Foreach container add a Data Flow task. In the Data Flow task modify your connection manager to use an expression to set the ConnectionString property. I think you have to specify an existing file at design time when setting the connection manager, then at run-time it will use the expression.

  • Thanks guys, I found a link here on SSC specifically for this, which pretty much does what you are referring to:

    http://www.sqlservercentral.com/articles/SSIS/61987/

    __________________________________________________________________________________
    SQL Server 2016 Columnstore Index Enhancements - System Views for Disk-Based Tables[/url]
    Persisting SQL Server Index-Usage Statistics with MERGE[/url]
    Turbocharge Your Database Maintenance With Service Broker: Part 2[/url]

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply