?
Solved

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

Posted on 2013-10-24
3
Medium Priority
?
2,360 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 66

Expert Comment

by:Jim Horn
ID: 39598068
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
ID: 39604564
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
ID: 39616229
It's the only solution that works
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lessons learned during ten years of interviewing for SQL Server Integration Services (SSIS) and other Extract-Transform-Load (ETL) contract roles and two years of staff manager interviewing contractors.
My client has a dictionary table. They're defining a list of standard naming convention. Now, they are requiring my team to provide us a mechanism how to match new incoming data with existing data in their system.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

801 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