I have a script task where i change the connection string for a db, however, it is missing one vital piece of information which is the server that the package itself is running on.
is there a way to retrieve the name of the server from a c# script?
i know in sql i can do select @@servername, but i need the package to check the name of the server that it(dtsx) is running on which is not the sql server.
i know this is an odd request, but there are many options, here are the ones that i am researching now:
+Through A Batch CMD whose results i could store in a pkg level variable
+Through a c# script
+SQL if it is possible
any other ways anyone knows of would be greatly appreciated.
EDIT/UPDATE: I found a couple of ways to do this:
C#: public string host = System.Environment.MachineName.ToString();
cmd: hostname ...-->then store in pkg variable
While you can use .NET to get the server name, the traditional SSIS way is to use the pre-existing "System::MachineName" package variable (as an aside, note that you might have to click the "Show System Variables" button to see it in the package Variables window.) Assuming SSIS 2008 and C# (2005/VB provides the same variable):
1) Add the variable name "System::MachineName" (without the quotes) to the script task editor ReadOnlyVariables property
2) Inside the script you access the variable like this:
Dts.Variables["System::MachineName"].Value.ToString()
Hope it helps. Kristian
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With