SSIS 2008: Write to a text file.

I am troubleshooting Data Flow in an SSIS package.  I want to write to a text file.  I am taking the package in steps.  As an example:

1)  Connection Manager
2)  If successful - write passed to text file else write error to text file

Then test additional steps:

1)  Connection Manager
2)  Export Data to Excel
3)  If successful - write passed to text file else write error to text file

Thanks


LVL 2
CipherISAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CottonSwabCommented:
The simplest way to accomplish this is to add a Script Component inside a Data Flow Task with a type of 'transform' and add some code such as the following in the Input0_ProcessInputRow method.  Sub in whatever connection type you are trying to use for SqlConnection as appropriate:

using( StreamWriter writer = new StreamWriter( "C:\test.txt" ) )
        {
            try 
	        {	        
                using (SqlConnection conn = Connections.MyConnection.AcquireConnection(null) as SqlConnection)
                {
                    writer.WriteLine("connection succeeded");       
                }
            }
	        catch (Exception ex)
	        {
        		writer.WriteLine("connection failed - exception was " + ex.Message);
	        }
        }

Open in new window


As far as viewing the results in Excel, you shouldn't need to go through the work of passing it out to a csv file yourself, add a dummy component as the next step in the flow and add a data viewer in between them.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CipherISAuthor Commented:
while that would work - i am troubleshooting a package that somoene else wrote.  It is failing.  So I cant to just write a script after their component runs to let me know if what happened.  So the above script wouldn't work for what i'm tyring to do
0
CipherISAuthor Commented:
i did just try to create a script and connect a task i receive the following error:

"The destination component does not have any availalbe inputs for use in creating a path"
0
The 7 Worst Nightmares of a Sysadmin

Fear not! To defend your business’ IT systems we’re going to shine a light on the seven most sinister terrors that haunt sysadmins. That way you can be sure there’s nothing in your stack waiting to go bump in the night.

CottonSwabCommented:
The type of script you need to create (source, destination, or transformation) depends on where in the data flow it is sitting.  Perhaps I misled you in having you create a script transformation, as that would be most appropriate if you already had some data coming in to the script.  If your script is first, try creating a source transformation instead.
0
CipherISAuthor Commented:
my script is not first.  Its doing a database connection then I want to write to the text file.  I am writing to troubleshoot so I can find the error.
0
CipherISAuthor Commented:
I used the dataviewer which provided me with what i needed.
0
CipherISAuthor Commented:
Data Viewer is the solution to the problem.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.