Solved

SSIS Pass Excel path variable from a script task to a data flow task

Posted on 2013-10-24
3
2,210 Views
Last Modified: 2016-02-11
Hi All,

I took this C# code from the internet which basically gets the latest file path I have in a directory.

 public void Main()
        {
            string[] files = System.IO.Directory.GetFiles(@"C:\SSIS\Files");
            System.IO.FileInfo finf;
            DateTime lastDate = new DateTime();
            string lastFile = string.Empty;
            foreach (string f in files)
            {
                finf = new System.IO.FileInfo(f);
                if (finf.CreationTime > lastDate)
                {
                    lastDate = finf.CreationTime;
                    lastFile = f;
                }
            }

            Dts.Variables["User::LastFile"].Value = lastFile;


            Dts.TaskResult = (int)ScriptResults.Success;
        }

Open in new window


I put the code in a Script Task and I was successfully able to get the path of the latest Excel file which is written to the [User::LastFile] variable.


However, I want to pass this variable to an Excel connection manager. I've done it through Expressions (in properties of the Excel connection manager)>ExcelFilePath property and chosen the variable as @[User::LastFile] variable.

When I setup an Excel Source Task and try to select the name of the Excel Sheet it says: Invalid argument.

Can anyone suggest how I can get my variable Excel full path successfully into an Excel connection manager to work in a Data Flow task so that I can eventually import that Excel file?

Thanks

OS
0
Comment
Question by:onesegun
  • 2
3 Comments
 
LVL 65

Expert Comment

by:Jim Horn
Comment Utility
The VB.NET script task would go like this..
Public Sub Main()
Dts.Connections("YourExcelFileConnection").ConnectionString = Dts.Variables("LastFile").Value
End Sub

Open in new window

Not sure on the C# script..
0
 

Accepted Solution

by:
onesegun earned 0 total points
Comment Utility
Hi All,

I found this solution on the net and it works perfectly with my code.  A way to configure the  user variable that stores the Excel File path variable so that it can be used in a Data Flow Task. No further coding required.

http://dbaspot.com/sqlserver-dts/338698-sql-20005-ssis-dynamic-excel-path-connectionstring.html

Thanks,

OS
0
 

Author Closing Comment

by:onesegun
Comment Utility
It's the only solution that works
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now