In SSIS, can I write the value of a variable to a SQL table?
This seems like it should be easy to do, but I can't figure it out. In my Control Flow I have an Execute SQL task that populates an ADO Recordset variable. That works fine, the variable holds a list of server names. Then I have that connected to a Foreach Loop Container, which loops through the server names, connects to each server, reads some info, and writes that to a table. That also works, except for those servers that it can't connect to. So here's what I'd like to do: before I connect to the server, write the value of the variable (which contains the server name) to a table in SQL, along with getdate() so I know when it started trying to connect. How do I just write the value of a variable to a table? If I just use an OLE DB Destination, there are no input columns. My best thought was to use a Script Component and somehow get that value, and then somehow make it an output column, which I then connect to the OLE DB Destination as an input column?? If I do this in a C# Script Component: MessageBox.Show(Dts.Variables["myVariable"].Value.ToString()); it works just fine, so I know my variable is there an available. Any suggestions appreciated!
April 14th, 2011 1:03pm

You can do it using the Script Task, but I think it is much faster to code with using Execute SQL Task. Just map your variable to an input parameter of the Execute SQL Task which will execute SQL similar to: DECLARE @dt DATETIME DECLARE @SrvName SET @dt = GETDATE() SET @SrvName = ? Exec dbo.spInsertConnAttempt @dt @SrvName Arthur My Blog
Free Windows Admin Tool Kit Click here and download it now
April 14th, 2011 1:10pm

I'm agree with Arthur, use Execute sql task in the foreach loop as first task to do this insertion. Note that if you use OLEDB Connection in the execute sql task, you should use question mark ( ? ) as parameter marker in the sql statement and pass parameters in the parameters tab with parameter names which are zero based index ( 0,1,2,..) this is more information about how to work with execute sql task with different connection managers: http://technet.microsoft.com/en-us/library/ms140355.aspxhttp://www.rad.pasfu.com
April 14th, 2011 1:34pm

Thanks guys, that's extremely helpful! Can you recommend a good, comprehensive book on SSIS?
Free Windows Admin Tool Kit Click here and download it now
April 14th, 2011 3:19pm

BOL and the samples a good start for the beginners.Regards and good Wishes, Deepak.
April 14th, 2011 3:28pm

this is really good book in SSIS: http://www.wrox.com/WileyCDA/WroxTitle/Professional-Microsoft-SQL-Server-2008-Integration-Services.productCd-0470247959.htmlhttp://www.rad.pasfu.com
Free Windows Admin Tool Kit Click here and download it now
April 14th, 2011 3:29pm

this is really good book in SSIS: http://www.wrox.com/WileyCDA/WroxTitle/Professional-Microsoft-SQL-Server-2008-Integration-Services.productCd-0470247959.html Second that one, it is a really great book. After you've finished it, I can truly recommand this (more advanced) book: http://www.amazon.com/Microsoft-Server-2008-Integration-Services/dp/0470525762/ref=sr_1_1?ie=UTF8&s=books&qid=1302809388&sr=1-1MCTS, MCITP - Please mark posts as answered where appropriate.
April 14th, 2011 3:32pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics