Question

SSIS export to new excel file

Asked by: Payfprmance

I am trying to build an SSIS dataflow to export a recordset of data to a fresh excel file with a dynamic name suffixed with datetime stamp and cannot change the ConnectionString, it continuously errors, please advise.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-01-13 at 06:35:35ID24047576
Tags

SSIS

,

excel

Topics

SSIS

,

Server Software

,

Enterprise Software

Participating Experts
3
Points
500
Comments
28

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. ssis
    Source Table A column a column b column c Table B column f column z column h Destination Table Y column j column k column l Table e column o column n column r I would like to move records from multiple tables (tableA & table B) from the source to (table y & Tabl...
  2. SSIS package, or other way, to export multiple tables to …
    Hi, I need to export multiple tables to csv files. These tables are extracts of data created using SQL Queries for the purpose ofexporting to csv files and sent to an external service center. I'm assuming I'll need to use an SSIS package to accomplish this. I've exported th...
  3. SSIS
    validation of date field in SSIS tool
  4. SSIS
    How can I develop a SSIS package to transfer data that is in one sql database to another sql database?
  5. SSIS recordset
    HI, Expert In my SSIS package (SQL Server 2008), I would like to have a table to store my intermediate result. and let this result can be used everywhere in the package. (1) To my best of knowledge, SSIS does not have struct or array variable. So is the only way to do it i...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: HoggZillaPosted on 2009-01-13 at 06:38:09ID: 23363026

You setup an Excel Connection Manager (ExCM), in the properties for the ExCM click on Expressions. Choose ConnectionString and then build the ConnectionString using the Expression Builder. Is that where you are at this point?

 

by: PedroCGDPosted on 2009-01-13 at 06:39:01ID: 23363045

Let me know which the error you have.
I can attach here a sample SSIS Project.
You are importing from SQL to excel, and want the connectionstring with the datetime in the filename, and the file created dinamically, is this correct?!

 

by: HoggZillaPosted on 2009-01-13 at 06:49:53ID: 23363178

Be sure to put two back-slashes for every back-slash because they are considered an escape character in Expressions. C:\Temp would look like C:\\Temp.

 

by: HoggZillaPosted on 2009-01-13 at 06:52:08ID: 23363203

Here is an example of an Expression to create just a filename - not the path, adding the curent date:

"dw_batch_"
+   (DT_WSTR, 2) MONTH( GETDATE() )
+   (DT_WSTR, 2) DAY( GETDATE()  )
+   (DT_WSTR, 4)  YEAR( GETDATE()  )

 

by: PayfprmancePosted on 2009-01-13 at 06:56:35ID: 23363243

I have tried the connection string dynamic build, as the SSIS package has other functional expressions for other abilities, I have been reading about dropping tables and recreating tables in the excel connection mananger, but every time I dynamically assign variables for that component I get:SSIS Error Code DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER

 

by: PedroCGDPosted on 2009-01-13 at 06:57:42ID: 23363259

put delay=true on conenction properties

 

by: PayfprmancePosted on 2009-01-13 at 06:59:29ID: 23363278

@PedroCGD:

correct, I want to generate a new excel document suffixed with datetime that gets kicked off from a job to populate the newly generated excel document, I put @[User:FileName] which is generated dynamically, depending on what the SSIS was asked to do, it has 7 other evaluation dataflows, depending on what Extract variable was passed to it, now one of them has to make excel instead of a flat file, and I cant seem to assign dynamic variables to the excel connection manager like I can to the database connector, and the flat file destination handlers.

 

by: HoggZillaPosted on 2009-01-13 at 07:00:10ID: 23363292

This will add Date and Time in the form of a String to an FileName. In This case I am writting to C:\Temp\Excel\myfile_YYYYMMDD_HHMISS.xls

"C:\\Temp\\Excel\\myfile_"
+ (DT_WSTR, 4) YEAR( GETDATE()  )
+ RIGHT("0" + (DT_WSTR, 2) MONTH( GETDATE()  ) , 2 )
+ RIGHT("0" + (DT_WSTR, 2) DAY( GETDATE()  ) , 2 )
+ "_"
+ RIGHT("0" + (DT_WSTR, 2)DATEPART( "HH" , GETDATE()  ) , 2 )
+ RIGHT("0" + (DT_WSTR, 2)DATEPART( "MI" , GETDATE()  ) , 2 )
+ RIGHT("0" + (DT_WSTR, 2)DATEPART( "SS" , GETDATE()  ) , 2 )
+ ".xls"

 

by: PayfprmancePosted on 2009-01-13 at 07:01:54ID: 23363310

Delay validation = true for excel connection mananger already

 

by: PedroCGDPosted on 2009-01-13 at 07:03:32ID: 23363341

ok... I'm doing an example for you!
just a moment

 

by: HoggZillaPosted on 2009-01-13 at 07:05:32ID: 23363371

Debug: SSIS Error Code DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER

What is the value you are trying to assign at the point of the error?

How are you trying to assign the ConnectionString dynamically? Excel Connection Manager expressions?

You have not even got here yet, but you will also need to run a create table statement on your new Excel File to hold the data.

Also, I have found the best choice is to create a template Excel document. This already has the "table" created. You use a File System Task to copy the template to your new FileName, then when your Excel Connection Manager looks for that file it is already there -ready for data.

 

by: PedroCGDPosted on 2009-01-13 at 07:18:05ID: 23363521

OK...
To create the excel file dinamically, you should have the file already created in the destiantion. SSIS doenst create the excel file for you.

1. You can should have a excel file to copy for a destination directory that will be renamed using the date format with a script task. Could be a template file as Hogg suggested.

Give feedback

 

by: PayfprmancePosted on 2009-01-13 at 08:08:25ID: 23364138

ConnectionString=@[User::FileName]

I have read that you need a template file to map to, thats fine, but all I can get it to do is append the template and/or make the dynamically named file that has no data. I dont mind the template idea if it will only make itself a fresh file every time the job is called, create the header column names in row 1, and then append all the relevant data into the excel document, ExcelDocument_yyyymmdd.xls.

 

by: PayfprmancePosted on 2009-01-13 at 08:12:34ID: 23364185

@HoggZilla: I have the script already designed to create the dynamically named file:

Dts.VariableDispenser.LockOneForWrite("User::FileName", vars)
            vars(0).Value = strEnv + strFilePath + strFileName_Prefix + MyDate.ToString("yyyyMMdd_HHmmss") + ".xls"

however, when I assign [User::FileName] to the excel connection manager connection string, this is when I get the error.SSIS Error Code DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER

 

by: HoggZillaPosted on 2009-01-13 at 08:18:19ID: 23364266

Ok, first thing I need you is put a breakpoint at the time you populate the FileName variable, look in the Locals window and get me the value of that variable.

Next, before going to the Data Flow Task to write to the Excle File, you will need to put a File System Task in to make a copy of your template Excel File - the one you can write to without a "dynamic" connectionstring, and copy it to the new FileName from your variable.

Then, let's validate that your ConnectionString expression is setup correctly. You have the connectionstring defined by an expression in the Excle Connection Manager properties?

Let's validate these first and then go from there. This is a very common procedure what you are trying to do, but there are many "gotchas" in getting it done.

 

by: PayfprmancePosted on 2009-01-13 at 08:23:24ID: 23364330

OK, had not thought of the file system task to create a duplicate. My destination is biztalk consumption, so placing a template there will instantly get devoured by biztalk.

"the one you can write to without a "dynamic" connectionstring, and copy it to the new FileName from your variable."

are you stating that I read the template .xls into a variable inside the SSIS? wont the file system task allow me to copy the template from a 'safe zone' on the biztalk to the 'landing zone' area, and will it stay long enough for me to append data to it? Also, wouldnt I have to generate the filenaming convention prior to the file system task so that the excel connection will know what file to update?

The connection string expression is configured in excel connection manager as an expression.

 

by: PayfprmancePosted on 2009-01-13 at 08:26:36ID: 23364371

filename break:

c:\PROVIDERUPDATE\OXFORD\ProvUpd_PL_datetimestamp.xls

 

by: PayfprmancePosted on 2009-01-13 at 08:27:24ID: 23364379

and dynamically built from package variables set in the job:

@[User::Env]+@[User::FilePath]+@[User::FileName_Prefix]

 

by: HoggZillaPosted on 2009-01-13 at 08:31:05ID: 23364424

"the one you can write to without a "dynamic" connectionstring, and copy it to the new FileName from your variable."

are you stating that I read the template .xls into a variable inside the SSIS? wont the file system task allow me to copy the template from a 'safe zone' on the biztalk to the 'landing zone' area, and will it stay long enough for me to append data to it? Also, wouldnt I have to generate the filenaming convention prior to the file system task so that the excel connection will know what file to update?

The connection string expression is configured in excel connection manager as an expression.

When you first build the package, before you try writing to a "dynamic" file - the one that we are trying to create, you first wirte to a specific xls file. Maybe on your c:\temp or wherever. But that file is your beginning of the template. So, once you have written to that file, validated it works, then save it as your template. Something like MyTemplate.xls. Highlight all of the rows below the Heading and right click - delete. Make sure it deletes the rows, not just the data. And that is your template - ready to start writing at Row2.

 

by: PedroCGDPosted on 2009-01-13 at 08:32:18ID: 23364442

I'm almost done you SSIS example... just one more moment

 

by: HoggZillaPosted on 2009-01-13 at 08:33:45ID: 23364465

and dynamically built from package variables set in the job:

@[User::Env]+@[User::FilePath]+@[User::FileName_Prefix]

OK, so that is fine - I really prefer something more stable - like a specific path, but that works. For debugging, put in a message box to show you that value everytime before calling the Data Flow - need to be sure.

The File System Task, or Script Task if you prefer, should create a new file from your Template using this new FileName value.

 

by: PayfprmancePosted on 2009-01-13 at 08:58:28ID: 23364757

ok, I have been able to export data to the .xls file, it appends to the template, so I can investigate that avenue. I look forward to the example PedroCGD offers.

Thanks guys, the SSIS package is for 7 clients, all get flat files, except this new requirement that one of our vendors wants .xls and not just .csv saved as .xls. This will be a weekly job that needs to generate a new .xls each week with the datetimestamp.

I appreciate all the help here, its nice for once to get intelligent information :)

 

by: PayfprmancePosted on 2009-01-13 at 09:05:12ID: 23364827

we have multiple environments with different folder structures, therefore I have to make the biztalk server, filepath, and filename_prefix dynamic for each job in each environment.

 

by: PedroCGDPosted on 2009-01-13 at 09:30:05ID: 23365085

Check the attached package.
Update the variable uvFilePath
Helped?
regards,
Pedro

 

by: PayfprmancePosted on 2009-01-13 at 09:36:15ID: 23365149

wahoo, yes, this explains how I can do this, thanks both for help.

 

by: PayfprmancePosted on 2009-01-13 at 09:37:48ID: 23365160

I split the points, thanks again.

 

by: PayfprmancePosted on 2009-01-13 at 11:43:19ID: 23366396

confirmed confirmation @PedroCGD: example works as designed. Took some 'tweaking', thanks.

 

by: MCITPPosted on 2009-07-24 at 10:29:48ID: 24937111

Keep in mind that in corp environments servers get renamed and deleted from time to time.
You can experience errors in your ssis package execution if this happens even if you are using configuration files or setting variables in SQL Job Agent.
To avoid this nasty little bugger you can do the following.

On the properties tab of each connection manager you will want to set the "Delay Validation" to True so that you can avoid errors when the package runs on a seporate evnrionment.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...