SSIS - Assign value to a variable - Need ServerName from DestinationConnectionOLEDB as @Enviro from email

  • I have an SSIS package that has multiple email task that informs of success or failure of package tasks... I have expressions in the email "subject" that I need to get two more parts in it... 1st is the server name the connection is using; when the dtsx package is executed instead of having three packages for test, training production; the connection is changed at runtime; I want to use my user variable or if there's a system that I can't find but whatever I need the connection "ServerName" to be sent in the email...

    "Package>>> " + @[System::PackageName] +" was executed at>>> " + (DT_WSTR, 40) @[System::StartTime] + " by user>>> " + @[System::UserName] + " on Machine>>> " + @[System::MachineName] + " Server>>>" + @[User::Enviro]

    @[User::Enviro] How to get the value to be the server name from the connection manger?

    2nd would be good to know for me to use... if I add another User:TotalRecordsAdded how to set the value from the insert task to the user variable??

    Thank you,

    Barry

  • There may be a better way to get the server name, but the way I do it is run an SQL task and query @@SERVERNAME, then store that into a package-level variable from the result-set.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • Barry

    How do you configure the server name for the connection string? Do you use a dtsConfig file, or a SQL table, or is it hard coded? Does the server name change during package execution (in other words, does the package loop through several servers)? Gus's way will certainly work, but if there's a way to use an existing variable then I think that would be better than incurring a connection to the database.

    For your second question, I'd use the OUTPUT clause in your INSERT statement to populate a table variable, the do a SELECT COUNT(*) FROM that variable - that's assuming you're not writing millions of rows at a time into the table?

    John

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply