Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Dynamic Excel File Source Expand / Collapse
Author
Message
Posted Wednesday, May 27, 2009 9:52 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, November 8, 2010 10:20 AM
Points: 5, Visits: 42
What are the steps necessary to pass the Excel Source the excel file name as a variable? I've tried this a few different ways now and have had issues each way.

I've been trying to get this working for days! I've read a couple of long threads that involve a ForEach Loop Container to get multiple excel files and I've stepped thru them and am still stuck. I only wish to load one file per run. The format and location of the Excel File will never change - just the file name.

Here's what I've tried most recently:

1. Create Variable
Variable Name: FileName
Scope: Package
Data Type: String
Value: F:\apps\excel\Expense_Report_Form.xls

2. Run Package Nomally (w/o variable)
Excel Source: I set this up to point to the Excel File and tested with the Data Conversion and OLE DB Destination. Execute the package and it runs as expected. Moves Excel data to SQL Server.

3. Create expression (Connection Manager)
In the connection manager for the excel source create a expression
Property: ConnectionString
Expression: "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + @[User::FileName] +";Extended Properties=\"Excel 8.0;HDR=YES\";"

When I click evaluate expression it returns the following:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\apps\excel\Expense_Report_Form.xls;Extended Properties="Excel 8.0;HDR=YES";


As soon as I setup the expression the excel source gets a red X with error "an OLE DB error has occurred." If I try and execute the package it fails at that step. What am I missing here?? Right now I have delay validation set to "false" on the connection manager properties.

I am beyond frustrated at this point. I would greatly appreciate any advice you have to offer. Thanks in advance


Post #724773
Posted Wednesday, May 27, 2009 10:24 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 10:12 AM
Points: 5,259, Visits: 12,195
Delay validation should be set to True, not False, if the source file does not exist until run-time.

You could approach this a different way. Set up a hard-coded connection to, say, Data.xls and as the first part in your package, copy the dynamically named Excel file to it, overwriting what is already there.

Then allow the process to run using data.xls, which will always exist and your validation problems should go away.

Phil



Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

When you ask a question (and please do ask a question: "My T-SQL does not work" just doesn't cut it), please provide enough information for us to understand its context.
Post #724781
Posted Wednesday, May 27, 2009 11:24 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, November 8, 2010 10:20 AM
Points: 5, Visits: 42
Thanks for the reply Phil! I completely rebuilt the package, set delay validation = false..and it runs without error!

One more question. I'm trying to execute the package from a SP. What's the proper syntax to pass the variable from the SP to the SSIS package? My overall goal is to call the SSIS package programatically from an asp.net application. So I'll be passing the filename as a varaible from the program.

Here's what I have so far:

AS
DECLARE @cmd varchar(1000)
DECLARE @SSISpath varchar(1000)
DECLARE @ReturnCode int

set @SSISpath = 'F:\apps\SSIS Packages\ExcelImport.dtsx'

set @cmd= 'dtexec /F "' + @SSISpath + '"'
set @cmd = @cmd + ' /SET \Package.Variables[User::FileName].Properties[Value];"'

EXEC @ReturnCode = master..xp_cmdshell @cmd

Again, thanks for all your help!
Post #724802
Posted Thursday, November 8, 2012 4:31 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Tuesday, November 18, 2014 9:35 AM
Points: 86, Visits: 519
Hi I have same problem, I could not follow you could you please explan little more detail what to do.

It would be really great help, I spend, 5 hrs on this. In .cvs works perfect
Post #1382764
Posted Friday, November 9, 2012 12:30 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 8:55 AM
Points: 13,570, Visits: 11,383
Munabhai (11/8/2012)
Hi I have same problem, I could not follow you could you please explan little more detail what to do.

It would be really great help, I spend, 5 hrs on this. In .cvs works perfect


What's the issue? Any errors?




How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1382859
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse