Friday, February 17, 2012

DTS Variables..?

Is there a way to pass variables off to DTS by ADO.NET?
Such as a FileName to export to and/or a parameter for the export query?I tend to stay away from DTS... Some smartly written stored procs using Bulk Insert should do the trick...|||Yes,

I've done it from a stored procedure. Not sure how to go from ado.net directly to DTS.

Here a couple links to examples of using global variables. Not exactly what you need, but a start. It's what I used to get going and figured it out from there.

http://www.swynk.com/friends/green/textfile.asp
http://www.swynk.com/friends/green/DTSHowTo3.asp

http://www.sqldts.com/
http://www.dts2000.com/|||i did it this way from VB.NET...


Dim DTSPackage As New DTS.Package2
DTSPackage.LoadFromSQLServer(Config.Server, Config.User, Config.Pwd, DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_Default, "", "", "", DTSPackageName)
DTSPackage.GlobalVariables().Remove("ImportFileName")
DTSPackage.GlobalVariables().AddGlobalVariable("ImportFileName", ImportFileName)
DTSPackage.GlobalVariables().Remove("ExportCatalog")
DTSPackage.GlobalVariables().AddGlobalVariable("ExportCatalog", ExportCatalog)

i had a little trouble resetting the value of the global var in the DTS package if it already existed so i just removed it and re-added it. I'm sure theres a better way but...time was scarce.

Note: DTS Package Global Vars are case sensitive|||Thank you,

Got it late, but still works good!|||I'm having one little problem with this whole thread. What class library is the DTS.Package2 contained in? I can find no reference to it anywhere!|||DTS is a COM library that gets installed when you load SQL server
its named: dtspkg.dll
its titled: Microsoft DTSPackage Object Library
it lives in SQL Servers BINN folder|||Thanks a bunch. That's exactly what I needed. I've always been more on the SQL side than the .NET side. I searched everywhere for that reference and couldn't find a single one for DTS. Since it is only executed once a month (and never on the same day) I couldn't schedule it as I normally would.

No comments:

Post a Comment