I am working on a DTS SSIS package and aiming to use Teamcity buildserver (via Ruby / rake)… basically I want to customise for each environment (Dev, UAT, Prod) with different connection strings..
for example in Test I want to point to SQL2008Test, and in Dev SQL2008Dev. That means I’ll need to manipulate my dts package before its being deployed to the respective directory….
anyone got good experience with REXML – ruby?
This is my ruby code (with a rakefile)
config = {}
File.open(File.join(BUILD_SSIS_DIR, IRS_DSS_USER_PACKAGE)) do |config_file|
config = REXML::Document.new(config_file)
ConfigTasks.set_dts_constring_irs config, 'ConnectionString',
"Data Source=SQL2008DEV;Initial Catalog=IRSDEV;Provider=SQLNCLI10.1;Integrated Security=SSPI;Auto Translate=False;Application Name=SSIS-IRS DSS User Data Package-{3CC00FAB-7009-402D-AE03-2426AFC6B7ED}SQL2008 IRS Multiple Connection;"
end
and it calls
def self.set_dts_constring_irs(config_file, name, connection_string)
conn_string_element = config_file.root.elements['DTS:ConnectionManager/DTS:Property'];
conn_string_element['DTS:Name="ConnectionString"'] = connection_string
end
this is my DTS xml that I need to manipulate
<DTS:ConnectionManager>
<DTS:Property DTS:Name="DelayValidation">0</DTS:Property>
<DTS:Property DTS:Name="ObjectName">SQL2008 IRS Multiple Connection</DTS:Property>
<DTS:Property DTS:Name="DTSID">{3CC00FAB-7009-402D-AE03-2426AFC6B7ED}</DTS:Property>
<DTS:Property DTS:Name="Description"></DTS:Property>
<DTS:Property DTS:Name="CreationName">OLEDB</DTS:Property><DTS:ObjectData><DTS:ConnectionManager>
<DTS:Property DTS:Name="Retain">0</DTS:Property>
<DTS:Property DTS:Name="ConnectionString">Data Source=SQL2008DEV;Initial Catalog=IRSDEV;Provider=SQLNCLI10.1;Integrated Security=SSPI;Auto Translate=False;Application Name=SSIS-IRS DSS User Data Package-{3CC00FAB-7009-402D-AE03-2426AFC6B7ED}SQL2008 IRS Multiple Connection;</DTS:Property>
</DTS:ConnectionManager></DTS:ObjectData>
</DTS:ConnectionManager>
anyone got thoughts in terms of my work? e.g. how to use REXML to drill down the elements / attributes of connectionstring I need??
I am assuming you want to use REXML to find the connection string in an XML file, and to replace it with your own connection string. REXML lets you use XPath to find an element and to set it’s value:
which will output (some XML removed …):