<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ranjith Kumar S</title>
	<atom:link href="http://ranjithk.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://ranjithk.com</link>
	<description></description>
	<lastBuildDate>Thu, 26 Jan 2012 17:23:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>How to Transfer files from local machine to VPS or Dedicated Hosting Server without FTP</title>
		<link>http://ranjithk.com/2011/05/18/transfer-files-from-local-machine-to-vps-or-dedicated-hosting-server-using-rdp/</link>
		<comments>http://ranjithk.com/2011/05/18/transfer-files-from-local-machine-to-vps-or-dedicated-hosting-server-using-rdp/#comments</comments>
		<pubDate>Wed, 18 May 2011 18:29:31 +0000</pubDate>
		<dc:creator>Ranjith</dc:creator>
				<category><![CDATA[Windows Server]]></category>

		<guid isPermaLink="false">http://ranjithk.com/2011/05/18/transfer-files-from-local-machine-to-vps-or-dedicated-hosting-server-using-rdp/</guid>
		<description><![CDATA[This is simple with the remote desktop connection. You can share the local system drives or other local system resources with the remote server in few clicks as below. &#160; 1. Open RDP &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#160; 2. Expand Options and go to Local Resources Tab &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#160;&#160; &#160;&#160; 3. Click on More.. to open the Local [...]]]></description>
			<content:encoded><![CDATA[<p>This is simple with the remote desktop connection. You can share the local system drives or other local system resources with the remote server in few clicks as below.</p>
<p>&#160;</p>
<p>1. <strong><font color="#0080ff">Open RDP</font></strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <a href="http://ranjithk.com/wp-content/uploads/2011/05/image3.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://ranjithk.com/wp-content/uploads/2011/05/image_thumb3.png" width="359" height="220" /></a></p>
<p>&#160;</p>
<p>2. <strong><font color="#0080ff">Expand Options and go to Local Resources Tab</font></strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <a href="http://ranjithk.com/wp-content/uploads/2011/05/image4.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://ranjithk.com/wp-content/uploads/2011/05/image_thumb4.png" width="479" height="551" /></a>&#160;&#160; </p>
<p>&#160;&#160; </p>
<p>3. <strong><font color="#0080ff">Click on More.. to open the Local Devices and Resources selection wizard</font></strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <a href="http://ranjithk.com/wp-content/uploads/2011/05/image5.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://ranjithk.com/wp-content/uploads/2011/05/image_thumb5.png" width="482" height="500" /></a></p>
<p>Select the drives you want to have access from the VPS/Dedicated server and click on OK.</p>
<p>&#160;</p>
<p>4.<strong><font color="#0080ff"> Log on to your VPS/Dedicated server and go to My Computer</font></strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <a href="http://ranjithk.com/wp-content/uploads/2011/05/RDP.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="RDP" border="0" alt="RDP" src="http://ranjithk.com/wp-content/uploads/2011/05/RDP_thumb.png" width="519" height="371" /></a></p>
<p>You can see that the selected local drives are available for you to access directly from your server. This is very useful when you want to do the initial setup of the server with necessary software and there is no FTP setup available on the server .</p>
<p>&#160;</p>
<p>-Ranjith.</p>
]]></content:encoded>
			<wfw:commentRss>http://ranjithk.com/2011/05/18/transfer-files-from-local-machine-to-vps-or-dedicated-hosting-server-using-rdp/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>SQL Server 2008 new datetime types, functions and the conversions between them</title>
		<link>http://ranjithk.com/2010/04/27/sql-server-2008-new-datetime-types-functions-and-the-conversions-between-them/</link>
		<comments>http://ranjithk.com/2010/04/27/sql-server-2008-new-datetime-types-functions-and-the-conversions-between-them/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 04:59:36 +0000</pubDate>
		<dc:creator>Ranjith</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[DateTime2]]></category>
		<category><![CDATA[DateTimeOffset]]></category>
		<category><![CDATA[SWITCHOFFSET]]></category>
		<category><![CDATA[SYSUTCDATETIME]]></category>
		<category><![CDATA[time]]></category>
		<category><![CDATA[TODATETIMEOFFSET]]></category>

		<guid isPermaLink="false">https://ranjithk.wordpress.com/2010/04/27/sql-server-2008-new-datetime-types-functions-and-the-conversions-between-them/</guid>
		<description><![CDATA[Datetime Types in SQL Server 2005: Lets start with a quick look at the existing date time types in SQL Server. The datetime and smalldatetime, these two types are well known to us, So we wont be spending much time here. &#160; Data Type Representation Accuracy smalldatetime YYYY-MM-DD hh:mm:ss 1 minute datetime YYYY-MM-DD hh:mm:ss[.nnn] 0.00333 [...]]]></description>
			<content:encoded><![CDATA[<p><strong><span style="color: #0080c0">Datetime Types in SQL Server 2005:</span></strong></p>
<p>Lets start with a quick look at the existing date time types in SQL Server. The datetime and smalldatetime, these two types are well known to us, So we wont be spending much time here.</p>
<p>&#160;</p>
<table border="1" cellspacing="1" cellpadding="2" width="527">
<tbody>
<tr>
<td valign="top" width="133"><strong>Data Type</strong></td>
<td valign="top" width="218"><strong>Representation</strong></td>
<td valign="top" width="170"><strong>Accuracy</strong></td>
</tr>
<tr>
<td valign="top" width="133">smalldatetime</td>
<td valign="top" width="218">YYYY-MM-DD hh:mm:ss</td>
<td valign="top" width="170">1 minute</td>
</tr>
<tr>
<td valign="top" width="133">datetime</td>
<td valign="top" width="218">YYYY-MM-DD hh:mm:ss[.nnn]</td>
<td valign="top" width="170">0.00333 second</td>
</tr>
</tbody>
</table>
<p>&#160;</p>
<p>Though these types provide a whole lot of datetime functionality required for any database. The problem is that the date representation is always combined with the time in both the types and there is no way to represent the date only component or time only component in a database with out doing a lot of cast and convert.</p>
<p><strong><span style="color: #0080ff"></span></strong></p>
<p><strong><span style="color: #0080ff">New Datetime Types in SQL Server 2008</span></strong></p>
<p>SQL Server 2008 has introduced four new datetime data types for the date and time representations in SQL Server Databases.</p>
<p>&#160;</p>
<table border="1" cellspacing="1" cellpadding="2" width="533">
<tbody>
<tr>
<td valign="top" width="133"><strong>Data Type</strong></td>
<td valign="top" width="263"><strong>Representation</strong></td>
<td valign="top" width="131"><strong>Accuracy</strong></td>
</tr>
<tr>
<td valign="top" width="133">date</td>
<td valign="top" width="263">YYYY-MM-DD</td>
<td valign="top" width="131">1 day</td>
</tr>
<tr>
<td valign="top" width="133">time[n]</td>
<td valign="top" width="263">hh:mm:ss[.nnnnnnn]</td>
<td valign="top" width="131">100 nanoseconds</td>
</tr>
<tr>
<td valign="top" width="133">datetime2[n]</td>
<td valign="top" width="263">YYYY-MM-DD hh:mm:ss[.nnnnnnn]</td>
<td valign="top" width="131">100 nanoseconds</td>
</tr>
<tr>
<td valign="top" width="133">datetimeoffset[n]</td>
<td valign="top" width="263">YYYY-MM-DD hh:mm:ss[.nnnnnnn] [+|-]hh:mm</td>
<td valign="top" width="131">100 nanoseconds</td>
</tr>
</tbody>
</table>
<p>&#160;</p>
<p>The new <strong>Date</strong> type allows us to represents the date as an individual component with out the time field attached to it. And the <strong>Time</strong> type represents the Time as an individual component in databases. Note that the new Time type is at higher precision than the regular time in datetime type.</p>
<p>&#160;</p>
<p><strong>Datetime2</strong> can be considered as an extension to regular datetime type with the time representation at an accuracy of 100 nanoseconds than at the regular 0.00333 seconds. The datetime2 type can be used with a default precision (datetime2(7)) or can be used with a user defined precision like datetime2(n) format. If the time precision of datetime2 is set to 3 (datetime2(3)) which gives the exact equivalent representation of a regular datetime type.</p>
<p>&#160;</p>
<p><strong>DateTimeOffset</strong> is the combination of default datetime2 with the system <strong><a href="http://www.timeanddate.com/library/abbreviations/timezones/">time zone offset</a> </strong>attached to it. The time zone offset displayed based on the Operating System date, time and culture settings. The offset should be between –14:00 to +14:00. The DateTimeOffset type does not support the day light saving times.</p>
<p>&#160;</p>
<p>Here is my machine current datetimeoffset value <strong>2010-04-25 23:24:07.7086518 +05:30.</strong> Notice that the time zone offset returned is +05:30 i.e. IST (Indian Standard Time) attached to datetime2 data.</p>
<p><strong><span style="color: #0080c0"></span></strong></p>
<p><strong><span style="color: #0080c0">New Date and Time Functions</span></strong></p>
<table border="1" cellspacing="1" cellpadding="2" width="523">
<tbody>
<tr>
<td valign="top" width="200">SYSDATETIME()</td>
<td valign="top" width="318">Similar to GETDATE() but it returns the current system date as new datetime2(7) type</td>
</tr>
<tr>
<td valign="top" width="200">SYSUTCDATETIME()</td>
<td valign="top" width="318">Similar to GETUTCDATE() but it returns the current system date in UTC as a new datetime2(7) type</td>
</tr>
<tr>
<td valign="top" width="200">SYSDATETIMEOFFSET()</td>
<td valign="top" width="318">Returns the current system date time as DateTime2(7) with system time zone offset attached to it</td>
</tr>
<tr>
<td valign="top" width="200">SWITCHOFFSET(expr, tz)</td>
<td valign="top" width="318">Function to convert the datetimeoffset in one time zone to a datetimeoffset in another timezone</td>
</tr>
<tr>
<td valign="top" width="200">TODATETIMEOFFSET(expr, tz)</td>
<td valign="top" width="318">Function to convert the datetime, datetime2 or datetimeoffset to a datetimeoffset with the specified time zone</td>
</tr>
</tbody>
</table>
<p><strong><span style="color: #0080c0"></span></strong></p>
<p><strong><span style="color: #0080c0"></span></strong></p>
<p><strong><span style="color: #0080c0">Conversions between different datetime types</span></strong></p>
<p><strong><span style="color: #0080c0"></span></strong><strong>1. How to convert datetime or datetime2 to datetimeoffset with specified time zone?</strong></p>
<pre class="code"><span style="color: blue">SELECT </span><span style="color: magenta">GETDATE</span><span style="color: gray">(), </span><span style="color: magenta">TODATETIMEOFFSET</span><span style="color: gray">(</span><span style="color: magenta">GETDATE</span><span style="color: gray">(), </span><span style="color: red">'+08:30'</span><span style="color: gray">)
 </span><span style="color: green">-- results: 2010-04-26 00:18:36.927  | 2010-04-26 00:18:36.927 +08:30

</span><span style="color: blue">SELECT </span><span style="color: magenta">SYSDATETIME</span><span style="color: gray">(), </span><span style="color: magenta">TODATETIMEOFFSET</span><span style="color: gray">(</span><span style="color: magenta">SYSDATETIME</span><span style="color: gray">(), </span><span style="color: red">'+05:30'</span><span style="color: gray">)
</span><span style="color: green">-- results: 2010-04-26 00:18:36.9316407 | 2010-04-26 00:18:36.9316407 +05:30</span></pre>
<p>TODATETIMEOFFSET() combines the specified datetime or datetime2 to the specified time zone offset.</p>
<p>&#160;</p>
<p><strong>2. How to convert the datetimeoffset in one time zone to datetimeoffset in other time </strong><strong>zone?</strong></p>
<pre class="code"><span style="color: green">-- my current system time in IST (GMT + 5:30)
</span><span style="color: blue">SELECT </span><span style="color: magenta">SYSDATETIMEOFFSET</span><span style="color: gray">()
       </span><span style="color: green">-- 2010-04-26 00:32:48.1838343 +05:30

-- IST (GMT + 5:30) converted to North America PST (GMT - 8:00)
</span><span style="color: blue">SELECT </span><span style="color: magenta">SWITCHOFFSET</span><span style="color: gray">(</span><span style="color: magenta">SYSDATETIMEOFFSET</span><span style="color: gray">(), </span><span style="color: red">'-08:00'</span><span style="color: gray">)
       </span><span style="color: green">-- 2010-04-25 11:02:48.1838343 -08:00

-- IST (GMT + 5:30) converted to Europe BST (GMT + 1:00)
</span><span style="color: blue">SELECT </span><span style="color: magenta">SWITCHOFFSET</span><span style="color: gray">(</span><span style="color: magenta">SYSDATETIMEOFFSET</span><span style="color: gray">(), </span><span style="color: red">'+01:00'</span><span style="color: gray">)
       </span><span style="color: green">-- 2010-04-25 20:02:48.1838343 +01:00</span></pre>
<p><strong>3. How to convert local datetime or datetime2 to UTC (Coordinated Universal Time)?</strong></p>
<pre class="code"><span style="color: blue">DECLARE </span>@LocalDateTime <span style="color: blue">datetime
DECLARE </span>@TimeZoneOffset <span style="color: blue">INT

</span><span style="color: green">-- convert my current system datetime to UTC
</span><span style="color: blue">SET </span>@LocalDateTime <span style="color: gray">= </span><span style="color: magenta">GETDATE</span><span style="color: gray">()
     </span><span style="color: green">-- 2010-04-26 00:44:19.107

-- get the timezone offset of the system
</span><span style="color: blue">SET </span>@TimeZoneOffset <span style="color: gray">= </span><span style="color: magenta">DATEDIFF</span><span style="color: gray">(</span>MI<span style="color: gray">, </span><span style="color: magenta">SYSDATETIME</span><span style="color: gray">(),</span><span style="color: magenta">SYSUTCDATETIME</span><span style="color: gray">())
     </span><span style="color: green">-- 330 mins (i.e. 5:30 )

-- get the utc datetime
</span><span style="color: blue">SELECT </span><span style="color: magenta">DATEADD</span><span style="color: gray">(</span>MI<span style="color: gray">,</span>@TimeZoneOffset<span style="color: gray">, </span>@LocalDateTime<span style="color: gray">)
      </span><span style="color: green">-- 2010-04-25 19:14:19.107 </span></pre>
<p><strong>4. How to convert datetimeoffset to UTC?</strong></p>
<pre class="code"><span style="color: blue">DECLARE </span>@DTO <span style="color: blue">DATETIMEOFFSET
</span><span style="color: green">-- convert my system datetimeoffset to UTC
</span><span style="color: blue">SET </span>@DTO <span style="color: gray">= </span><span style="color: magenta">SYSDATETIMEOFFSET</span><span style="color: gray">()
</span><span style="color: green">-- 2010-04-26 00:50:35.3701337 +05:30

-- switch offset to '+00:00' i.e. UTC
</span><span style="color: blue">SELECT </span><span style="color: magenta">SWITCHOFFSET</span><span style="color: gray">(</span>@DTO<span style="color: gray">, </span><span style="color: red">'+00:00'</span><span style="color: gray">)
      ,</span><span style="color: magenta">CAST</span><span style="color: gray">(</span><span style="color: magenta">SWITCHOFFSET</span><span style="color: gray">(</span>@DTO<span style="color: gray">, </span><span style="color: red">'+00:00'</span><span style="color: gray">) </span><span style="color: blue">AS DATETIME2</span><span style="color: gray">)
</span><span style="color: green">-- 2010-04-25 19:20:35.3701337 +00:00  | 2010-04-25 19:20:35.3701337</span></pre>
<p><strong>5. Other simple conversions?</strong></p>
<pre class="code"><span style="color: blue">SELECT </span><span style="color: magenta">CAST</span><span style="color: gray">(</span><span style="color: magenta">GETDATE</span><span style="color: gray">() </span><span style="color: blue">AS Time</span><span style="color: gray">)
      ,</span><span style="color: magenta">CAST</span><span style="color: gray">(</span><span style="color: magenta">GETDATE</span><span style="color: gray">() </span><span style="color: blue">as date</span><span style="color: gray">)
      ,</span><span style="color: magenta">CAST</span><span style="color: gray">(</span><span style="color: magenta">SYSDATETIMEOFFSET</span><span style="color: gray">() </span><span style="color: blue">AS datetime2</span><span style="color: gray">)
 </span><span style="color: green">-- results: 01:03:35.5700000 | 2010-04-26 | 2010-04-26 01:03:35.5971486

-- get timezone offset from datetimeoffset
</span><span style="color: blue">SELECT </span><span style="color: magenta">DATEPART</span><span style="color: gray">(</span>TZ<span style="color: gray">, </span><span style="color: magenta">SYSDATETIMEOFFSET</span><span style="color: gray">())
 </span><span style="color: green">-- results: 330 (number of minutes)</span></pre>
<p>The new date time types in SQL Server 2008 are more portable than datetime or smalldatetime and it is recommended to use them in the future development work.</p>
<p>&#160;</p>
<p>-Ranjith.</p>
]]></content:encoded>
			<wfw:commentRss>http://ranjithk.com/2010/04/27/sql-server-2008-new-datetime-types-functions-and-the-conversions-between-them/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Dynamically getting the execution status of a SQL Server Agent Job</title>
		<link>http://ranjithk.com/2010/04/23/dynamically-getting-the-execution-status-of-a-sql-server-agent-job/</link>
		<comments>http://ranjithk.com/2010/04/23/dynamically-getting-the-execution-status-of-a-sql-server-agent-job/#comments</comments>
		<pubDate>Fri, 23 Apr 2010 06:01:27 +0000</pubDate>
		<dc:creator>Ranjith</dc:creator>
				<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[Insert EXEC statement cannot be nested]]></category>
		<category><![CDATA[Job Execution Status]]></category>
		<category><![CDATA[SQL Agent Job Status]]></category>

		<guid isPermaLink="false">http://ranjithk.wordpress.com/2010/04/23/dynamically-getting-the-execution-status-of-a-sql-server-agent-job/</guid>
		<description><![CDATA[This problem seems trivial but there is no straight forward way to get this information. If you have tried the INSERT into EXEC command to insert the results of the sp_help_job procedure into a temporary table like below then you are familiar with the below error. insert into #jobstatus execute msdb..sp_help_job Msg 8164, Level 16, [...]]]></description>
			<content:encoded><![CDATA[<p>This problem seems trivial but there is no straight forward way to get this information. If you have tried the INSERT into EXEC command to insert the results of the sp_help_job procedure into a temporary table like below then you are familiar with the below error.</p>
<p>insert into #jobstatus   <br />execute msdb..sp_help_job</p>
<p><span style="color: #ff0000">Msg 8164, Level 16, State 1, Procedure sp_get_composite_job_info, Line 72     <br />An INSERT EXEC statement cannot be nested.</span></p>
<p>So you can not directly insert the results to a temp table from this procedure. Here is a trick I have used using the OPENROWSET to get around with the INSERT EXEC problem. This query results can be stored into a temporary table or a table variable using the INSERT INTO or SELECT INTO command which can be used for further processing.</p>
<p><span style="color: blue">select </span>name<span style="color: gray">, </span><span style="color: blue">case when </span>current_execution_status <span style="color: gray">= </span>1 <span style="color: blue">then </span><span style="color: red">&#8216;Executing&#8217;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue">when </span>current_execution_status <span style="color: gray">= </span>2 <span style="color: blue">then </span><span style="color: red">&#8216;Waiting For Thread&#8217;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue">when </span>current_execution_status <span style="color: gray">= </span>3 <span style="color: blue">then </span><span style="color: red">&#8216;Between Retries&#8217;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue">when </span>current_execution_status <span style="color: gray">= </span>4 <span style="color: blue">then </span><span style="color: red">&#8216;Idle&#8217;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue">when </span>current_execution_status <span style="color: gray">= </span>5 <span style="color: blue">then </span><span style="color: red">&#8216;Suspended&#8217;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue">when </span>current_execution_status <span style="color: gray">= </span>6 <span style="color: blue">then </span><span style="color: red">&#8216;[Obsolete]&#8216;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue">when </span>current_execution_status <span style="color: gray">= </span>7 <span style="color: blue">then </span><span style="color: red">&#8216;PerformingCompletionActions&#8217;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: blue">else </span><span style="color: gray">NULL </span><span style="color: blue">end as </span>[status]&#160; <span style="color: blue">from     <br />&#160;&#160; openrowset</span><span style="color: gray">(</span><span style="color: red">&#8216;SQLNCLI&#8217;</span><span style="color: gray">, </span><span style="color: red">&#8216;Server=(local);Trusted_Connection=yes;&#8217;</span><span style="color: gray">,</span><span style="color: red">&#8216;EXEC msdb..sp_help_job&#8217;</span><span style="color: gray">)     <br /></span><span style="color: gray">&#160;</span></p>
<p>The OPENROWSET is one of the workarounds for the nested INSERT EXEC problem and many other solutions are proposed <a href="http://social.msdn.microsoft.com/forums/en-US/transactsql/thread/e66c9e71-4424-4cf3-920c-6725ffc40162/">here</a> (Thanks to <a href="http://sqlusa.com/">Kalman</a> for the workarounds).</p>
<p>&#160;</p>
<p>Hope it helps</p>
<p>- Ranjith</p>
]]></content:encoded>
			<wfw:commentRss>http://ranjithk.com/2010/04/23/dynamically-getting-the-execution-status-of-a-sql-server-agent-job/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>SQL Server 2008 R2 Free eBook from Microsoft Press</title>
		<link>http://ranjithk.com/2010/04/22/sql-server-2008-r2-free-ebook-from-microsoft-press/</link>
		<comments>http://ranjithk.com/2010/04/22/sql-server-2008-r2-free-ebook-from-microsoft-press/#comments</comments>
		<pubDate>Thu, 22 Apr 2010 08:05:52 +0000</pubDate>
		<dc:creator>Ranjith</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server Books]]></category>

		<guid isPermaLink="false">http://ranjithk.com/?p=165</guid>
		<description><![CDATA[Just came to know about this book. More details on the Microsoft Press Blog. You can download the ebook in XPS format here and in PDF format here. The book contains 10 chapters and 216 pages, like so: PART I   Database Administration CHAPTER 1   SQL Server 2008 R2 Editions and Enhancements 3 CHAPTER 2   Multi-Server [...]]]></description>
			<content:encoded><![CDATA[<p>Just came to know about this book. More details on the <a href="http://blogs.msdn.com/microsoft_press/archive/2010/04/14/free-ebook-introducing-microsoft-sql-server-2008-r2.aspx" target="_blank">Microsoft Press Blog.</a></p>
<p>You can download the ebook in <a href="http://go.microsoft.com/fwlink/?LinkId=189148">XPS format here</a> and in <a href="http://go.microsoft.com/fwlink/?LinkId=189147">PDF format here</a>.</p>
<p>The book contains 10 chapters and 216 pages, like so:</p>
<p>PART I   Database Administration</p>
<p>CHAPTER 1   SQL Server 2008 R2 Editions and Enhancements 3<br />
CHAPTER 2   Multi-Server Administration 21<br />
CHAPTER 3   Data-Tier Applications 41<br />
CHAPTER 4   High Availability and Virtualization Enhancements 63<br />
CHAPTER 5   Consolidation and Monitoring 85</p>
<p>PART II   Business Intelligence Development</p>
<p>CHAPTER 6   Scalable Data Warehousing 109<br />
CHAPTER 7   Master Data Services 125<br />
CHAPTER 8   Complex Event Processing with StreamInsight 145<br />
CHAPTER 9   Reporting Services Enhancements 165<br />
CHAPTER 10   Self-Service Analysis with PowerPivot 189</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://ranjithk.com/2010/04/22/sql-server-2008-r2-free-ebook-from-microsoft-press/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Script to drop all objects of a Schema in SQL Server</title>
		<link>http://ranjithk.com/2010/01/31/script-to-drop-all-objects-of-a-schema/</link>
		<comments>http://ranjithk.com/2010/01/31/script-to-drop-all-objects-of-a-schema/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 18:09:26 +0000</pubDate>
		<dc:creator>Ranjith</dc:creator>
				<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[Clean schema]]></category>
		<category><![CDATA[Drop Schema]]></category>
		<category><![CDATA[Drop Schema Objects]]></category>
		<category><![CDATA[SQL Schema]]></category>

		<guid isPermaLink="false">http://ranjithk.wordpress.com/2010/01/31/script-to-drop-all-objects-in-a-schema/</guid>
		<description><![CDATA[I have spent almost 3 hours to complete this script and test it for couple of sample scenarios during this weekend (31/01/10).&#160; It drops all the objects of the schema and then drops the schema itself. And automatically takes care of all the object dependencies with in the schema by dropping all of them in [...]]]></description>
			<content:encoded><![CDATA[<p>I have spent almost 3 hours to complete this script and test it for couple of sample scenarios during this weekend (31/01/10).&#160; It drops all the objects of the schema and then drops the schema itself. And automatically takes care of all the object dependencies with in the schema by dropping all of them in a specific order that will resolve the dependency issues.</p>
<p>&#160;</p>
<p>You can download the SP created using the script from <a href="http://ranjithk.com/wp-content/uploads/2010/06/cleanupschema.doc"><strong>here</strong> </a>(MS Word Document) or use this <a title="CleanupSchema" href="http://docs.google.com/View?id=dgwxbk97_155c5dpjqcc" target="_blank">Google Doc</a> link to view the script ( Thanks to Elias for the link ).</p>
<p>&#160;</p>
<p>The stored procedure takes two parameters; the @schemaname and the work test. Use @worktest equal to ‘t’ to print all the drop statements without executing them or specify anything else to execute the drop operations. The default option is ‘w’ i.e. it drops all the objects in the specified schema.</p>
<pre class="code"><span style="color: blue">EXEC </span>CleanUpSchema <span style="color: red">'MySchema'</span><span style="color: gray">, </span><span style="color: red">'t'        </span><span style="color: green">-- debug
</span><span style="color: blue">GO
EXEC </span>CleanupSchema <span style="color: red">'MySchema'</span><span style="color: gray">, </span><span style="color: red">'w'        </span><span style="color: green">-- work for me</span></pre>
<p>These are the known limitations of the script</p>
<ul>
<li>It can not drop a PK table in the schema with an XML index or Spatial index defined </li>
<li>It can not drop the schema which is referred by a XML schema collection</li>
</ul>
<p>Please let me know if you find any more issues with the script. I will list all of them here for others reference and will fix them to improve it further.</p>
<p>&#160;</p>
<p>Hope it helps</p>
<p>- Ranjith</p>
]]></content:encoded>
			<wfw:commentRss>http://ranjithk.com/2010/01/31/script-to-drop-all-objects-of-a-schema/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>How to get the File Group of a Table or an Index?</title>
		<link>http://ranjithk.com/2010/01/31/how-to-determine-the-file-group-of-a-table-or-a-index/</link>
		<comments>http://ranjithk.com/2010/01/31/how-to-determine-the-file-group-of-a-table-or-a-index/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 12:46:33 +0000</pubDate>
		<dc:creator>Ranjith</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[File Group of Table]]></category>
		<category><![CDATA[FileGroup of Index]]></category>

		<guid isPermaLink="false">http://ranjithk.wordpress.com/2010/01/31/how-to-determine-the-file-group-of-a-table-or-a-index/</guid>
		<description><![CDATA[The file group information of both Index and a Table is stored in the sys.indexes table. You might wonder how the tables file group is stored in sys.indexes metadata table. It is because when ever a clustered index is created on a table in SQL Server the physical data pages of the table will be made part of the clustered index i.e. the leaf nodes of the clustered index contain the physical table data. So the clustered index file group is the file group of the table.

If there is no clustered index on the table then it is represented as a HEAP with index_id equal to ZERO in sys.indexes table.

A clustered index is always the index with index_id equal to 1 and a non clustered index will always have index_id greater than 1 in sys.indexes table .

Below query gets the file group of the table Employee in HumanResources schema of AdventureWorks database.



SELECT d.name AS FileGroup FROM sys.filegroups d JOIN sys.indexes i ON i.data_space_id = d.data_space_id JOIN sys.tables t ON t.object_id = i.object_id WHERE i.index_id&#60;2 -- could be heap or a clustered table AND t.name= &#39;Employee&#39; AND t.schema_id = schema_id(&#39;HumanResources&#39;)



And below query gets the file group of the index ‘AK_Employee_rowguid’ on Employee table in HumanResources schema of AdventureWorks database.



SELECT d.name AS FileGroup FROM sys.filegroups d JOIN sys.indexes i ON i.data_space_id = d.data_space_id JOIN sys.tables t ON t.object_id = i.object_id WHERE i.name = &#39;AK_Employee_rowguid&#39;  AND t.name= &#39;Employee&#39; AND t.schema_id = schema_id(&#39;HumanResources&#39;)



Please note that schema_id is important otherwise both the queries might return multiple results if you have same table name on different schemas.



Hope it helps

:) ranjith :)]]></description>
			<content:encoded><![CDATA[<p>This might sound simple to SQL experts, Apart from the query I feel that the first paragraph of this post is useful to all. So read on.</p>
<p>&#160;</p>
<p>The file group information of both an Index and a Table are stored in the sys.indexes metadata table. You might wonder how the tables file group is stored in sys.indexes metadata table. It is because when ever a clustered index is created on a table in SQL Server sorts the physical data pages using the clustered index key and the data pages are made part of the clustered index i.e. the leaf nodes of the clustered index contain the physical table data. So the file group of the clustered index is the file group of the table.</p>
<p>&#160;</p>
<p><strong><font color="#0080ff">What if there is no clustered index on the table?</font></strong></p>
<p>If there is no clustered index on the table then it is represented as a HEAP with index_id equal to ZERO in sys.indexes table. At any point a clustered index with index_id equal to 1 or a heap with index_id equal to ZERO exists for a table in sys.indexes table.&#160; All non clustered indexes will have index_id greater than 1.</p>
<p>&#160;</p>
<p>Below query gets the file group of the table Employee in HumanResources schema of AdventureWorks database.</p>
<pre class="code"> <span style="color: blue">SELECT </span>d<span style="color: gray">.</span>name <span style="color: blue">AS </span>FileGroup
 <span style="color: blue">FROM </span><span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">filegroups </span>d
 <span style="color: gray">JOIN </span><span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">indexes </span>i
   <span style="color: blue">ON </span>i<span style="color: gray">.</span>data_space_id <span style="color: gray">= </span>d<span style="color: gray">.</span>data_space_id
 <span style="color: gray">JOIN </span><span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">tables </span>t
   <span style="color: blue">ON </span>t<span style="color: gray">.</span><span style="color: magenta">object_id </span><span style="color: gray">= </span>i<span style="color: gray">.</span><span style="color: magenta">object_id
</span><span style="color: blue">WHERE </span>i<span style="color: gray">.</span>index_id<span style="color: gray">&lt;</span>2                     <span style="color: green">-- could be heap or a clustered table
 </span><span style="color: gray">AND </span>t<span style="color: gray">.</span>name<span style="color: gray">= </span><span style="color: red">'Employee'
 </span><span style="color: gray">AND </span>t<span style="color: gray">.</span><span style="color: magenta">schema_id </span><span style="color: gray">= </span><span style="color: magenta">schema_id</span><span style="color: gray">(</span><span style="color: red">'HumanResources'</span><span style="color: gray">)</span></pre>
<p>And below query gets the file group of the index ‘AK_Employee_rowguid’ on Employee table in HumanResources schema of AdventureWorks database.</p>
<pre class="code"> <span style="color: blue">SELECT </span>d<span style="color: gray">.</span>name <span style="color: blue">AS </span>FileGroup
 <span style="color: blue">FROM </span><span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">filegroups </span>d
 <span style="color: gray">JOIN </span><span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">indexes </span>i
   <span style="color: blue">ON </span>i<span style="color: gray">.</span>data_space_id <span style="color: gray">= </span>d<span style="color: gray">.</span>data_space_id
 <span style="color: gray">JOIN </span><span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">tables </span>t
   <span style="color: blue">ON </span>t<span style="color: gray">.</span><span style="color: magenta">object_id </span><span style="color: gray">= </span>i<span style="color: gray">.</span><span style="color: magenta">object_id
</span><span style="color: blue">WHERE </span>i<span style="color: gray">.</span>name <span style="color: gray">= </span><span style="color: red">'AK_Employee_rowguid'        </span><span style="color: green">
 </span><span style="color: gray">AND </span>t<span style="color: gray">.</span>name<span style="color: gray">= </span><span style="color: red">'Employee'
 </span><span style="color: gray">AND </span>t<span style="color: gray">.</span><span style="color: magenta">schema_id </span><span style="color: gray">= </span><span style="color: magenta">schema_id</span><span style="color: gray">(</span><span style="color: red">'HumanResources'</span><span style="color: gray">)</span></pre>
<p>Please note that schema_id is important otherwise both the queries might return multiple results if you have same table name on different schemas.</p>
<p>&#160;</p>
<p>Hope it helps</p>
<p> &#8211; Ranjith</p>
]]></content:encoded>
			<wfw:commentRss>http://ranjithk.com/2010/01/31/how-to-determine-the-file-group-of-a-table-or-a-index/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Understanding SET QUOTED_IDENTIFIER ON/OFF and SET ANSI_NULLS ON/OFF</title>
		<link>http://ranjithk.com/2010/01/10/understanding-set-quoted_identifier-onoff/</link>
		<comments>http://ranjithk.com/2010/01/10/understanding-set-quoted_identifier-onoff/#comments</comments>
		<pubDate>Sun, 10 Jan 2010 15:12:40 +0000</pubDate>
		<dc:creator>Ranjith</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SET ANSI_NULL OFF]]></category>
		<category><![CDATA[SET ANSI_NULL ON]]></category>
		<category><![CDATA[SET QUOTED_IDENTIFIER OFF]]></category>
		<category><![CDATA[SET QUOTED_IDENTIFIER ON]]></category>

		<guid isPermaLink="false">http://ranjithk.wordpress.com/2010/01/10/understanding-set-quoted_identifier-onoff/</guid>
		<description><![CDATA[These are the two widely used SET options in SQL Server. Most developers explicitly set these options while creating Stored Procedures, Triggers and User Defined Functions but many are unclear on why we need to explicitly SET them? And why they are special compared to other options? Below is the typical usage of these options. [...]]]></description>
			<content:encoded><![CDATA[<p>These are the two widely used SET options in SQL Server. Most developers explicitly set these options while creating Stored Procedures, Triggers and User Defined Functions but many are unclear on why we need to explicitly SET them? And why they are special compared to other options?</p>
<p>Below is the typical usage of these options.</p>
<pre class="code"><span style="color: blue">SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE </span>SampleProcedure
<span style="color: blue">AS
BEGIN
 </span><span style="color: green">-- select employees
 </span><span style="color: blue">SELECT </span><span style="color: gray">* </span><span style="color: blue">FROM </span>HumanResources<span style="color: gray">.</span>Employee
<span style="color: blue">END</span></pre>
<p>Lets first understand what they exactly mean to SQL Server and then we will move on to why they are special.</p>
<p>&#160;</p>
<p><strong><span style="color: #0080ff">SET QUOTED_IDENTIFIER ON/OFF:</span></strong></p>
<p><strong><span style="color: #0080ff"></span></strong>It specifies how SQL Server treats the data that is defined in Single Quotes and Double Quotes. When it is set to ON any character set that is defined in the double quotes “” is treated as a T-SQL Identifier (Table Name, Proc Name, Column Name….etc) and the T-SQL rules for naming identifiers will not be applicable to it. And any character set that is defined in the Single Quotes ‘’ is treated as a literal.</p>
<pre style="width: 600px; height: 140px" class="code">

<span style="color: blue">SET QUOTED_IDENTIFIER ON
CREATE TABLE </span>&quot;SELECT&quot; <span style="color: gray">(</span>&quot;TABLE&quot; <span style="color: blue">int</span><span style="color: gray">)  </span><span style="color: green">-- SUCCESS
</span><span style="color: blue">GO</span>

<span style="color: blue">
SET QUOTED_IDENTIFIER ON
SELECT </span>&quot;sometext&quot; <span style="color: blue">AS </span>Value   <span style="color: green">-- FAIL because “sometext” is not a literal</span>
</pre>
<p>Though the <a href="http://11011.net/software/vspaste">“</a>SELECT” and “TABLE” are reserved keywords&#160; we are able to create the table because they are now treated as identifiers and the T SQL rules for identifier names are ignored.</p>
<p>When it is set to OFF any character set that is defined either in <strong>Single Quotes</strong> or in <strong>Double Quotes</strong> is treated as a literal.</p>
<pre style="width: 600px; height: 125px" class="code">

<span style="color: blue">SET QUOTED_IDENTIFIER OFF
CREATE TABLE </span><span style="color: red">&quot;SELECT&quot;</span><span style="color: gray">(</span><span style="color: red">“</span><span style="color: blue">TABLE</span><span style="color: red">” </span><span style="color: blue">int</span><span style="color: gray">) </span><span style="color: green">-- FAIL
</span><span style="color: blue">GO</span>

<span style="color: blue">
SET QUOTED_IDENTIFIER OFF
SELECT </span><span style="color: red">&quot;sometext&quot; </span><span style="color: blue">AS </span>Value    <span style="color: green">-- SUCCESS as “sometext” is treated as a literal</span>
</pre>
<p>You can clearly see the difference in CREATE TABLE and SELECT query. Here the CREATE TABLE fails because “SELECT” is a reserved keyword and it is considered as a literal. The default behavior is ON in any database.</p>
<p>&#160;</p>
<div class="csharpcode"><strong><span style="color: #0080ff">SET ANSI_NULLS ON/OFF:</span></strong></div>
<div>The ANSI_NULLS option specifies that how SQL Server handles the comparison operations with NULL values. When it is set to ON any comparison with NULL using = and &lt;&gt; will yield to false value. And it is the ISO defined standard behavior. So to do the comparison with NULL values we need to use IS NULL and IS NOT NULL. And when it is set to OFF any comparison with NULL using = and &lt;&gt; will work as usual i.e. NULL = NULL returns true and 1= NULL returns false.</div>
<pre style="width: 600px; height: 224px" class="code"><span style="color: blue">SET ANSI_NULLS ON
IF </span><span style="color: gray">NULL = NULL
 </span><span style="color: blue">PRINT </span><span style="color: red">'same'
</span><span style="color: blue">ELSE
 PRINT </span><span style="color: red">'different'
</span><span style="color: green">--result:  different

</span><span style="color: blue">SET ANSI_NULLS ON
IF </span><span style="color: gray">NULL IS NULL
 </span><span style="color: blue">PRINT </span><span style="color: red">'same'
</span><span style="color: blue">ELSE
 PRINT </span><span style="color: red">'different'
</span><span style="color: green">-- result: same</span></pre>
<pre style="width: 600px; height: 106px" class="code"><span style="color: blue">SET ANSI_NULLS OFF
IF </span><span style="color: gray">NULL = NULL
 </span><span style="color: blue">PRINT </span><span style="color: red">'same'
</span><span style="color: blue">ELSE
 PRINT </span><span style="color: red">'different'
</span><span style="color: green">--result:  same (now NULL = NULL works as 1=1)</span></pre>
<p>The default behavior is ON in any database. As per BOL 2008 this option will always be set to ON in the future releases of SQL Server and any explicit SET to OFF will result an error. So avoid explicitly setting this option in future development work.</p>
<p>&#160;</p>
<p><strong><span style="color: #0080ff">Why are these two options Special?:</span></strong></p>
<p>These two SET options are special because whenever a stored procedure or a Trigger or a User Defined Function is created or modified with these options explicitly SET; SQL Server remembers those settings in the associated object metadata. And every time the object (stored procedure,Trigger..etc.) is executed SQL server uses the stored settings irrespective of what the current user session settings are. So the behavior of the stored procedure is not altered by the calling session settings and the usage of the SET option behavior inside the SP is always guaranteed.</p>
<p>You can get any procedure or trigger or function settings for these options from the sys..sql_modules metadata table.</p>
<pre class="code"><span style="color: blue">SELECT </span>uses_ansi_nulls<span style="color: gray">, </span>uses_quoted_identifier
 <span style="color: blue">FROM </span><span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">sql_modules </span><span style="color: blue">WHERE </span><span style="color: magenta">object_id </span><span style="color: gray">= </span><span style="color: magenta">object_id</span><span style="color: gray">(</span><span style="color: red">'SampleProcedure'</span><span style="color: gray">)</span></pre>
<p>And if you need to guarantee the behavior for other SET options like SET ARITHABORT inside the SP then you need to SET them inside the procedure. The scope of the options specified inside the procedure are only applicable until the procedure completes its execution.</p>
<p>&#160;</p>
<p>Hope it helps.</p>
<p>- Ranjith</p>
]]></content:encoded>
			<wfw:commentRss>http://ranjithk.com/2010/01/10/understanding-set-quoted_identifier-onoff/feed/</wfw:commentRss>
		<slash:comments>34</slash:comments>
		</item>
		<item>
		<title>Automating Web Deployment using Windows Installer XML (WIX)</title>
		<link>http://ranjithk.com/2009/12/17/automating-web-deployment-using-windows-installer-xml-wix/</link>
		<comments>http://ranjithk.com/2009/12/17/automating-web-deployment-using-windows-installer-xml-wix/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 10:49:17 +0000</pubDate>
		<dc:creator>Ranjith</dc:creator>
				<category><![CDATA[Windows Installer XML]]></category>
		<category><![CDATA[Web Deployment Project]]></category>
		<category><![CDATA[WIX Web Deployment]]></category>
		<category><![CDATA[WIX web installer]]></category>
		<category><![CDATA[WIX Web Setup]]></category>

		<guid isPermaLink="false">http://ranjithk.wordpress.com/2009/12/17/automating-web-deployment-using-windows-installer-xml-wix/</guid>
		<description><![CDATA[Deployment of web sites is usually done by copying the compiled ASP.NET web site files into the target virtual directory by using Copy Web Site or Publish web site features in Visual Studio and by manually creating and configuring the Web Site in IIS.

Though this method is simple, it involves lot of manual effort in verifying the Pre Requisites, Creating/Modifying or Configuring the Web sites in IIS. We can automate this whole process by building a simple Windows Installer Package using WIX in the Visual Studio itself while working on the development of your site.

The installer using WIX can

· Check for all the Pre Requisites (OS Version, IIS version, and .NET Framework etc..) before applying any changes

· Create/Modify the web site, Application Pool and configures it in IIS

· Provide the features like Install, Un-Install, Repair and change to the site

· Remove everything that is created (Web Site, Physical Directories) on Un Install and leaves the target server in clean state with just few button clicks

· Rollback all the changes in case of failure



Create a Sample Web Site:

Let’s create a simple website and add a Web Deployment Project to the Web Site. We will build the installer package to deploy this web site on to the target server.



Fig 1: Sample web site and its Web Deployment project

Right click on Web Deployment project and open the Property pages to set up the output location for our compiled web site files. Leave the default value which is set to project output folder. This location we will be the source for our installer package to pick up the required files while building the installer package.



Fig 2: Web Deployment Project property pages





Fig 3: Files in Web Deployment project output folder



Authoring Installer for our Sample Web Site:

We need to install the WIX 3.0 version from http://sourceforge.net/projects/wix/files/ to add the WIX plug-in to the Visual Studio. (Please use WIX documentation for basic understanding on Directory, Component and Feature elements in WIX source files)

Now add the new WIX project to our solution. After you add it the solution looks like this



Fig 4: The web site and the set up project together in one solution

The Product.wxs is the WIX Source File which we will modify shortly to define our package components. Before that we need to add reference to WixIISExtension.dll and WixUtilExtension.dll to our WIX Project. Now open the Product.wxs and add the following xml namespaces to get the intelliscenece for WIX IIS and other elements.







The default directory structure defined in WIX source file maps to “C:Program FilesApplicationName” which specifies the target install location for our package i.e. the location on target server which will have all the output files from our MyWebSite_deploy project (See Fig 3).



Now add the following under the INSTALLLOCATION directory to define our first component

<!-- root level files –&#62;-->

The component MySite_root_Files defines all the files that are directly needs to be copied under the INSTALLLOCATION. The  element specifies the actual file that needs to be copied and the source attribute specifies the complete source path of the file.

Source="$(var.SolutionDir)MyWebSite_deploy$(var.Configuration)Default.aspx"

$(var.SolutionDir) is a WIX pre-processor which gives the Solution folder path to the WIX compiler

$(var.Configuration) is another pre-processor which specifies the Active Configuration of the solution (i.e. Debug &#124; Release)

Along with the files Default.aspx and Web.Config we also have bin folder in project output directory which needs to be created under the install location. So create the folder mapping INSTALLLOCATIONbin by adding the directory element like below under the INSTALLLOCATION directory. And define the component and file or Directory element for each of the files and directories under the bin folder as we have done for INSTALLLOCATION directory.

<!-- bin directory –&#62;-->

The same way we can add any number of directories and files mapping from source to the target location.

Setting up IIS web site:

So far we have seen how to move files from source to the target location by using the Directory, File and Component elements. But how can we configure IIS?

WIX has an API or an Extension (WIXIISExtension.dll) to interact with IIS. Remember that we have already added reference to this to our WIX Project. Add another component under the INSTALLLOCATION directory to define the configuration to create a web site in IIS.
  <!-- define application pool -->  <!-- define web site -->


Most of the elements and their attributes in this component are self descriptive.

 define the domain user which can be referenced anywhere in the source file using the Id MyWebSite_AppPoolUser.

 creates the application pool with the name MyWebSiteApplication. The attribute Identity = “Other” specifies that this application pool uses Custom account for identity. And the user attribute specifies the ID of the domainusername created anywhere in the source file using

 and its child elements ,  and  define the complete web site in IIS. The Directory attribute of Web Site element is set to INSTALLLOCATION i.e. C:Program FilesMyWebSite which is our target location to copy the compiled ASP.NET files to run our Web Site.

The bindings IP, PORT and Host Header for our web site are specified by  element, and the mapping between the application pool MyWebSite_AppPool and the site is defined by  . The Default Dcoument and the Authentication are specified by .

So we have defined all the components (MySite_root_Files, MySite_bin_Directory, and MyWebSite_IISConfigure) that need to be installed on to the target server by our installer. But we know that every installer needs at least one feature which is a set of components that define one complete install feature i.e. our Web Site in this case. We have to define it using the feature element.  <!-- add the components comprise of this feature -->

That is it. We have completed authoring the installer package for our Web Site. Upon building the entire solution again our Set up project reads the compiled ASP.NET files from our Web Deployment Project out put folder and embeds them into a Windows Installer package which is created in the out put directory of our setup project.



Fig 5: Installer package in Setup project output location









We just need to copy this installer package to the target server and double click and wait for the job to be done.



Fig 6: while installing our setup file



Once the install is complete, open the IIS Manager to see that our web site running.



Summary:

The web deployment using WIX is simple, flexible, and gives a overall great web deployment experience.

Hope this gives you a start-up point]]></description>
			<content:encoded><![CDATA[<p>Deployment of web sites is usually done by copying the compiled ASP.NET web site files into the target virtual directory using Copy Web Site or Publish web site features in Visual Studio and manually creating and configuring the Web Site in IIS.</p>
<p>Though this method is simple, it involves lot of manual effort in verifying the Pre Requisites, Creating/Modifying or Configuring the Web sites in IIS. We can automate this whole process by building a simple Windows Installer Package using WIX.</p>
<p>WIX installer package</p>
<ul>
<li>Provides the features like Install, Un-Install, Repair and Remove to your Web Site similar to any other product install on your machine </li>
<li>You can check for all the Pre Requisites like OS Version, IIS version, and .NET Framework etc.. before proceeding with the deployment and inform the user about what happened with a nice UI </li>
<li>You can create a new web site, modify the existing web site,&#160; Create Application Pools and configures IIS </li>
<li>During the un-install you can remove everything that is created (Web Site, Physical Directories) on Install and leave the target server in clean state </li>
<li>You can rollback the install changes in case of a failure </li>
</ul>
<p><strong></strong></p>
<p><strong><span style="text-decoration: underline">Create a Sample Web Site:</span></strong></p>
<p>Let’s create a simple website and add a Web Deployment Project to it. We will build the installer package to deploy this web site on to the target server.</p>
<p><img style="padding-right: 10px; display: inline" class="alignnone" title="clip_image002" border="0" alt="clip_image002" src="http://ranjithk.com/wp-content/uploads/2009/11/clip_image002_thumb.jpg" width="244" height="227" /><strong> </strong></p>
<p>Fig 1: Sample web site and its Web Deployment project</p>
<p>&#160;</p>
<p>Right click on Web Deployment project and open the Property pages to set up the output location for our compiled web site files. Leave the default values for this demo which is set to the project output folder. This location we will be the source for our installer package to pick up the required files while building the installer package.</p>
<p><a href="http://ranjithk.com/wp-content/uploads/2009/11/clip_image004.jpg"><img style="display: inline; clear: left; padding-top: 10px" class="alignnone" title="clip_image004" border="0" alt="clip_image004" src="http://ranjithk.com/wp-content/uploads/2009/11/clip_image004_thumb.jpg" width="244" height="147" /></a><strong> </strong></p>
<p>Fig 2: Web Deployment Project property pages</p>
<p><strong></strong></p>
<p>Build the whole solution to see the output files in deployment project output location</p>
<p><a href="http://ranjithk.com.flax.arvixe.com/wp-content/uploads/2009/11/clip_image006.jpg"><img style="display: inline" title="clip_image006" border="0" alt="clip_image006" src="http://ranjithk.com/wp-content/uploads/2009/11/clip_image006_thumb.jpg" /></a></p>
<p>Fig 3: Files in Web Deployment project output folder</p>
<p>&#160;</p>
<p><strong><span style="text-decoration: underline">Authoring Installer for our Sample Web Site:</span></strong></p>
<p>Install the WIX 3.0 Visual Studio plug in from <a href="http://sourceforge.net/projects/wix/files/">http://sourceforge.net/projects/wix/files/</a>. And for basic understanding on the Directory, Component, Feature and other elements in WIX source files use the WIX documentation file in the installed location of the plug in or go to <a title="http://www.tramontana.co.hu/wix/" href="http://www.tramontana.co.hu/wix/">http://www.tramontana.co.hu/wix/</a>.</p>
<p>Once the plug in is installed add the new WIX project to our sample web site solution by going to add new project –&gt; Select WIX.</p>
<p>After you add it the solution looks like this</p>
<p><a href="http://ranjithk.com.flax.arvixe.com/wp-content/uploads/2009/11/clip_image008.jpg"><img style="display: inline" title="clip_image008" border="0" alt="clip_image008" src="http://ranjithk.com/wp-content/uploads/2009/11/clip_image008_thumb.jpg" /></a></p>
<p><strong>Fig 4: The web site and the set up project together in one solution</strong></p>
<p><strong></strong></p>
<p>The Product.wxs is the WIX Source File which we will modify shortly to define our package components. Before that add references to <strong>WixIISExtension.dll</strong> and <strong>WixUtilExtension.dll</strong> in WIX binaries location to our WIX Project.</p>
<p>Now open the Product.wxs and add the following xml namespaces to get the intelliscenece for WIX IIS and other elements.</p>
<pre><span style="color: blue">&lt;</span><span style="color: #a31515">Wix </span><span style="color: red">xmlns</span><span style="color: blue">=</span>&quot;<span style="color: blue">http://schemas.microsoft.com/wix/2006/wi</span>&quot;
     <span style="color: red">xmlns:iis</span><span style="color: blue">=</span>&quot;<span style="color: blue">http://schemas.microsoft.com/wix/IIsExtension</span>&quot;
     <span style="color: red">xmlns:util</span><span style="color: blue">=</span>&quot;<span style="color: blue">http://schemas.microsoft.com/wix/UtilExtension</span>&quot;<span style="color: blue">&gt;</span></pre>
<p>The default directory structure defined in Product.wxs maps to “C:Program FilesApplicationName”<strong> </strong>which specifies the target install location for our package i.e. the location on target server which will have all the output files from our MyWebSite_deploy project (See Fig 3).</p>
<p>Under the INSTALLLOCATION directory add the following to define our first component</p>
<pre><span style="color: blue">&lt;!-- </span><span style="color: green">root level files –</span><span style="color: blue">&gt;</span>
<span style="color: blue">&lt;</span><span style="color: #a31515">Component </span><span style="color: red">Id</span><span style="color: blue">=</span>&quot;<span style="color: blue">MySite_root_Files</span>&quot; <span style="color: red">Guid</span><span style="color: blue">=</span>&quot;<span style="color: blue">E06FD7E9-8360-4e78-B10F-3F53E88FE1FB</span>&quot;<span style="color: blue">&gt;
 &lt;</span><span style="color: #a31515">File </span><span style="color: red">Id</span><span style="color: blue">=</span>&quot;<span style="color: blue">MySite_Default_aspx</span>&quot; <span style="color: red">Source</span><span style="color: blue">=</span>&quot;<span style="color: blue">$(var.SolutionDir)MyWebSite_deploy$(var.Configuration)</span><span style="color: blue"> Default.aspx</span>&quot;<span style="color: blue">/&gt;
 &lt;</span><span style="color: #a31515">File </span><span style="color: red">Id</span><span style="color: blue">=</span>&quot;<span style="color: blue">MySite_Web_Config</span>&quot; <span style="color: red">Source</span><span style="color: blue">=</span>&quot;<span style="color: blue">$(var.SolutionDir)MyWebSite_deploy$(var.Configuration)Web.Config</span>&quot;<span style="color: blue">/&gt;
&lt;/</span><span style="color: #a31515">Component</span><span style="color: blue">&gt;</span></pre>
<p>&#160;</p>
<p>The component <strong>MySite_root_Files</strong> defines all the files that are directly needs to be copied under the INSTALLLOCATION. The &lt;File/&gt; element specifies the actual file that needs to be copied and the source attribute specifies the complete source path of the file.</p>
<pre><span style="color: red">Source</span><span style="color: blue">=</span>&quot;<span style="color: blue">$(var.SolutionDir)MyWebSite_deploy$(var.Configuration)Default.aspx</span>&quot;</pre>
<p><strong>$(var.SolutionDir)</strong> is a WIX pre-processor which gives the Solution folder path to the WIX compiler</p>
<p><strong>$(var.Configuration)</strong> is another pre-processor which specifies the Active Configuration of the solution (i.e. Debug | Release)</p>
<p>Along with the files Default.aspx and Web.Config we also have bin folder in project output directory which needs to be created under the install location. So create the folder mapping INSTALLLOCATIONbin by adding the directory element under the INSTALLLOCATION directory. And define the component and file or Directory element for each of the files and directories under the bin folder as we have done for INSTALLLOCATION directory.</p>
<p><strong></strong></p>
<pre><span style="color: blue">&lt;!-- </span><span style="color: green">bin directory –</span><span style="color: blue">&gt;</span>
<span style="color: blue"> &lt;</span><span style="color: #a31515">Directory </span><span style="color: red">Id</span><span style="color: blue">=</span>&quot;<span style="color: blue">MySite_bin_Directory</span>&quot; <span style="color: red">Name</span><span style="color: blue">=</span>&quot;<span style="color: blue">bin</span>&quot;<span style="color: blue">&gt;
   &lt;</span><span style="color: #a31515">Component </span><span style="color: red">Id</span><span style="color: blue">=</span>&quot;<span style="color: blue">MySite_bin_Files</span>&quot; <span style="color: red">Guid</span><span style="color: blue">=</span>&quot;<span style="color: blue">2ECC2543-856E-4ca7-8DB3-D1657245A41E</span>&quot;<span style="color: blue">&gt;
     &lt;</span><span style="color: #a31515">File </span><span style="color: red">Id</span><span style="color: blue">=</span>&quot;<span style="color: blue">MYSite_MySite_deploy_dll</span>&quot; <span style="color: red">Source</span><span style="color: blue">=</span>&quot;<span style="color: blue">$(var.SolutionDir)MyWebSite_deploy$(var.Configuration)</span>
<span style="color: blue">             binMyWebSite_deploy.dll</span>&quot;<span style="color: blue">&gt;
      &lt;/</span><span style="color: #a31515">File</span><span style="color: blue">&gt;
    &lt;/</span><span style="color: #a31515">Component</span><span style="color: blue">&gt;
  &lt;/</span><span style="color: #a31515">Directory</span><span style="color: blue">&gt;</span></pre>
<p>&#160;</p>
<p>The same way we can add any number of directories and files mapping from source to the target location.</p>
<p><strong><span style="text-decoration: underline">Setting up IIS web site:</span></strong></p>
<p>So far we have seen how to move files from source to the target location by using the Directory, File and Component elements. But how can we configure IIS?</p>
<p>WIX has an API or an Extension (WIXIISExtension.dll) to interact with IIS. Remember that we have already added reference to this to our WIX Project. Add another component under the INSTALLLOCATION directory to define the configuration to create a web site in IIS.</p>
<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">ComponentId</span><span style="color: blue">=</span>&quot;<span style="color: blue">MyWebSite_IISConfigure</span>&quot; <span style="color: red">Guid</span><span style="color: blue">=</span>&quot;<span style="color: blue">5146762F-0E78-47d2-A105-6E18E2993619</span>&quot; <span style="color: red">KeyPath</span><span style="color: blue">=</span>&quot;<span style="color: blue">yes</span>&quot;<span style="color: blue">&gt;
  &lt;</span><span style="color: #a31515">util:UserId</span><span style="color: blue">=</span>&quot;<span style="color: blue">MyWebSite_AppPoolUser</span>&quot; <span style="color: red">Name</span><span style="color: blue">=</span>&quot;<span style="color: blue">domainusername</span>&quot; <span style="color: red">Password</span><span style="color: blue">=</span>&quot;<span style="color: blue">pwd</span>&quot;<span style="color: blue">/&gt;

  &lt;!--</span><span style="color: green">define application pool</span><span style="color: blue">--&gt;
  &lt;</span><span style="color: #a31515">iis:WebAppPool </span><span style="color: red">Id</span><span style="color: blue">=</span>&quot;<span style="color: blue">MyWebSite_AppPool</span>&quot; <span style="color: red">Name</span><span style="color: blue">=</span>&quot;<span style="color: blue">MyWebSiteApplication</span>&quot;
                  <span style="color: red">Identity</span><span style="color: blue">=</span>&quot;<span style="color: blue">other</span>&quot; <span style="color: red">User</span><span style="color: blue">=</span>&quot;<span style="color: blue">MyWebSite_AppPoolUser</span>&quot;
                  <span style="color: red">RecycleMinutes</span><span style="color: blue">=</span>&quot;<span style="color: blue">120</span>&quot; <span style="color: blue">/&gt;

  &lt;!--</span><span style="color: green">define web site</span><span style="color: blue">--&gt;
  &lt;</span><span style="color: #a31515">iis:WebSite </span><span style="color: red">Id</span><span style="color: blue">=</span>&quot;<span style="color: blue">MyWebSite_Website</span>&quot; <span style="color: red">Description</span><span style="color: blue">=</span>&quot;<span style="color: blue">MyWebSite</span>&quot;
               <span style="color: red">AutoStart</span><span style="color: blue">=</span>&quot;<span style="color: blue">yes</span>&quot; <span style="color: red">StartOnInstall</span><span style="color: blue">=</span>&quot;<span style="color: blue">yes</span>&quot; <span style="color: red">ConfigureIfExists</span><span style="color: blue">=</span>&quot;<span style="color: blue">yes</span>&quot;
               <span style="color: red">Directory</span><span style="color: blue">=</span>&quot;<span style="color: blue">INSTALLLOCATION</span>&quot; <span style="color: red">ConnectionTimeout</span><span style="color: blue">=</span>&quot;<span style="color: blue">360</span>&quot; <span style="color: blue">&gt;

    &lt;</span><span style="color: #a31515">iis:WebAddress </span><span style="color: red">Id</span><span style="color: blue">=</span>&quot;<span style="color: blue">MYSite_Bindings</span>&quot; <span style="color: red">IP</span><span style="color: blue">=</span>&quot;<span style="color: blue">xx.xx.x.xxx</span>&quot; <span style="color: red">Port</span><span style="color: blue">=</span>&quot;<span style="color: blue">80</span>&quot; <span style="color: red">Header</span><span style="color: blue">=</span>&quot;<span style="color: blue">MyWebSite</span>&quot; <span style="color: blue">/&gt;
    &lt;</span><span style="color: #a31515">iis:WebApplication </span><span style="color: red">Id</span><span style="color: blue">=</span>&quot;<span style="color: blue">MY_WebApp</span>&quot; <span style="color: red">Name</span><span style="color: blue">=</span>&quot;<span style="color: blue">MY Web Site</span>&quot; <span style="color: red">WebAppPool</span><span style="color: blue">=</span>&quot;<span style="color: blue">MyWebSite_AppPool</span>&quot;
                        <span style="color: red">ScriptTimeout</span><span style="color: blue">=</span>&quot;<span style="color: blue">360</span>&quot; <span style="color: blue">/&gt;
    &lt;</span><span style="color: #a31515">iis:WebDirProperties </span><span style="color: red">Id</span><span style="color: blue">=</span>&quot;<span style="color: blue">MyWebSite_Properties</span>&quot; <span style="color: red">AnonymousAccess</span><span style="color: blue">=</span>&quot;<span style="color: blue">yes</span>&quot; <span style="color: red">WindowsAuthentication</span><span style="color: blue">=</span>&quot;<span style="color: blue">no</span>&quot;
           <span style="color: red">DefaultDocuments</span><span style="color: blue">=</span>&quot;<span style="color: blue">Default.aspx</span>&quot; <span style="color: blue">/&gt;
  &lt;/</span><span style="color: #a31515">iis:WebSite</span><span style="color: blue">&gt;
  &lt;/</span><span style="color: #a31515">Component</span><span style="color: blue">&gt;</span></pre>
<p>&#160;</p>
<p>Most of the elements and their attributes in this component are self descriptive.</p>
<p>&lt;Util:User/&gt; define the domain user which can be referenced anywhere in the source file using the Id MyWebSite_AppPoolUser<strong>. </strong><strong></strong></p>
<p>&lt;iis:WebAppPool/&gt; creates the application pool with the name MyWebSiteApplication. The attribute Identity = “Other” specifies that this application pool uses Custom account for identity. And the user attribute specifies the ID of the domainusername created anywhere in the source file using &lt;Util:User/&gt;</p>
<p>&lt;iis:WebSite/&gt; and its child elements &lt;iis:WebAddress/&gt;, &lt;iis:WebApplication/&gt; and &lt;iis:WebDirProperties/&gt; define the complete web site in IIS. The Directory attribute of Web Site element is set to INSTALLLOCATION i.e. C:Program FilesMyWebSite which is our target location to copy the compiled ASP.NET files to run our Web Site.</p>
<p>The bindings IP, PORT and Host Header for our web site are specified by &lt;iis:WebAddress/&gt; element, and the mapping between the application pool MyWebSite_AppPool and the site is defined by &lt;iis:WebApplication/&gt; . The Default Dcoument and the Authentication are specified by &lt;iis:WebDirProperties/&gt;.</p>
<p>So we have defined all the components (MySite_root_Files, MySite_bin_Directory, and MyWebSite_IISConfigure) that need to be installed on to the target server by our installer. But we know that every installer needs at least one feature which is a set of components that define one complete install feature i.e. our Web Site in this case. We have to define it using the feature element.</p>
<pre>  <span style="color: blue">&lt;</span><span style="color: #a31515">Feature </span><span style="color: red">Id</span><span style="color: blue">=</span>&quot;<span style="color: blue">ProductFeature</span>&quot; <span style="color: red">Title</span><span style="color: blue">=</span>&quot;<span style="color: blue">My WebSite</span>&quot; <span style="color: red">Level</span><span style="color: blue">=</span>&quot;<span style="color: blue">1</span>&quot;<span style="color: blue">&gt;
     &lt;!-- </span><span style="color: green">add the components comprise of this feature </span><span style="color: blue">--&gt;
     &lt;</span><span style="color: #a31515">ComponentRef </span><span style="color: red">Id</span><span style="color: blue">=</span>&quot;<span style="color: blue">MySite_root_Files</span>&quot;<span style="color: blue">/&gt;
     &lt;</span><span style="color: #a31515">ComponentRef </span><span style="color: red">Id</span><span style="color: blue">=</span>&quot;<span style="color: blue">MySite_bin_Files</span>&quot;<span style="color: blue">/&gt;
     &lt;</span><span style="color: #a31515">ComponentRef </span><span style="color: red">Id</span><span style="color: blue">=</span>&quot;<span style="color: blue">MyWebSite_IISConfigure</span>&quot;<span style="color: blue">/&gt;
  &lt;/</span><span style="color: #a31515">Feature</span><span style="color: blue">&gt;
</span></pre>
<p>That is it. We have completed authoring the installer package for our Web Site. Upon building the entire solution again our Set up project reads the compiled ASP.NET files from our Web Deployment Project out put folder and embeds them into a Windows Installer package which is created in the out put directory of our setup project.</p>
<p>&#160;</p>
<p><a href="http://ranjithk.com.flax.arvixe.com/wp-content/uploads/2009/11/clip_image0024.jpg"><img style="display: inline" title="clip_image002[4]" border="0" alt="clip_image002[4]" src="http://ranjithk.com/wp-content/uploads/2009/11/clip_image0024_thumb.jpg" /></a></p>
<p>Fig 5: Installer package in Setup project output location</p>
<p>We just need to copy this installer package to the target server and double click and wait for the job to be done.</p>
<p><strong><a href="http://ranjithk.com.flax.arvixe.com/wp-content/uploads/2009/11/clip_image0044.jpg"><img style="display: inline" title="clip_image004[4]" border="0" alt="clip_image004[4]" src="http://ranjithk.com/wp-content/uploads/2009/11/clip_image0044_thumb.jpg" /></a></strong></p>
<p>Fig 6: while installing our setup file<strong> </strong></p>
<p><strong></strong></p>
<p>Once the install is complete, open the IIS Manager to see that our web site running.</p>
<p><strong></strong></p>
<p><strong><span style="text-decoration: underline">Summary:</span></strong></p>
<p>The web deployment using WIX is simple, flexible, and gives a overall great web deployment experience.</p>
<p>&#160;</p>
<p>Hope it helps</p>
<p>- Ranjith</p>
]]></content:encoded>
			<wfw:commentRss>http://ranjithk.com/2009/12/17/automating-web-deployment-using-windows-installer-xml-wix/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>WIX: Update Application Configuration Files during Installation</title>
		<link>http://ranjithk.com/2009/11/06/wix-update-application-configuration-files-during-installation/</link>
		<comments>http://ranjithk.com/2009/11/06/wix-update-application-configuration-files-during-installation/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 16:54:33 +0000</pubDate>
		<dc:creator>Ranjith</dc:creator>
				<category><![CDATA[Windows Installer XML]]></category>
		<category><![CDATA[WIX Config]]></category>
		<category><![CDATA[WIX XML]]></category>

		<guid isPermaLink="false">http://ranjithk.wordpress.com/2009/11/06/wix-update-application-configuration-files-during-installation-2/</guid>
		<description><![CDATA[Often we need to modify application configuration files during installation of the application. Generally to set some application settings, or modify database connection strings etc. We can do this in WIX by using the &#60;util:XmlFile/&#62; custom actions. To use these custom actions we need to reference WIXUtilExtension to the setup project. &#60;util:XmlFile Id=&#34;UpdateConnectionString&#34; File=&#34;[#FileID]&#34; ElementPath=&#34;XPATH&#34; [...]]]></description>
			<content:encoded><![CDATA[<p>Often we need to modify application configuration files during installation of the application. Generally to set some application settings, or modify database connection strings etc. We can do this in WIX by using the &lt;util:XmlFile/&gt; custom actions. To use these custom actions we need to reference WIXUtilExtension to the setup project.</p>
<pre class="code"><span style="color: gray">&lt;</span><span style="color: blue">util:</span>XmlFile Id<span style="color: gray">=</span><span style="color: red">&quot;UpdateConnectionString&quot;
                    </span><span style="color: blue">File</span><span style="color: gray">=</span><span style="color: red">&quot;[#FileID]&quot;
                    </span>ElementPath<span style="color: gray">=</span><span style="color: red">&quot;XPATH&quot;
                    </span><span style="color: blue">Action</span><span style="color: gray">=</span><span style="color: red">&quot;setValue&quot;
                    </span>Value<span style="color: gray">=</span><span style="color: red">&quot;&quot;
        </span><span style="color: gray">&lt;/</span><span style="color: blue">util:</span>XmlFile<span style="color: gray">&gt;</span></pre>
<p>The File attribute specifies the ID of the configuration file which is defined using the &lt;File/&gt; element in WIX source file; ElementPath specifies the XPATH to an element in the configuration file which needs to be modified, Action specifies what to do with the element; it should be either createElement, deleteElement, setValue, or bulkSetValue. And the Value specifies the target value to be set to the element. Mostly we would use a Property that has been set by the installer UI sequence as a target value.</p>
<p>Below example shows how to modify the connection string DBConn and the application setting MySetting in the Web.Config file.</p>
<pre class="code"><span style="color: gray">&lt;</span>Component Id<span style="color: gray">=</span>”ConfigureWebConfig” <span style="color: blue">Guid</span><span style="color: gray">=</span>”<span style="color: gray">*</span>”<span style="color: gray">&gt;
 &lt;</span><span style="color: blue">File </span>Id<span style="color: gray">=</span>”MyConfigfile” <span style="color: gray">Source=</span>”$<span style="color: gray">(</span><span style="color: magenta">var</span><span style="color: gray">.</span>Configuration<span style="color: gray">)</span>web<span style="color: gray">.</span>config” KeyPath<span style="color: gray">=</span>”yes” <span style="color: gray">/&gt;

&lt;!</span><span style="color: green">-- update a connection string  --&gt;
</span><span style="color: gray">&lt;</span><span style="color: blue">util:</span>XmlFile Id<span style="color: gray">=</span><span style="color: red">&quot;UpdateConnectionString&quot;
  </span><span style="color: blue">File</span><span style="color: gray">=</span><span style="color: red">&quot;[#MyConfigfile]&quot;
  </span><span style="color: blue">Action</span><span style="color: gray">=</span><span style="color: red">&quot;setValue&quot;
  </span>ElementPath<span style="color: gray">=
  </span><span style="color: red">&quot;//configuration/connectionStrings/add[[]@name=’DBConn’[]]/@connectionString&quot;
  </span>Value<span style="color: gray">=</span><span style="color: red">&quot;Server=[DBSERVER];Database=[DBNAME];Integrated Security=SSPI;&quot;</span><span style="color: gray">/&gt;

&lt;!</span><span style="color: green">-- update an application setting  --&gt;
</span><span style="color: gray">&lt;</span><span style="color: blue">util:</span>XmlFile Id<span style="color: gray">=</span><span style="color: red">&quot;UpdateMySetting&quot;
  </span><span style="color: blue">File</span><span style="color: gray">=</span><span style="color: red">&quot;[#MyConfigfile]&quot;
  </span><span style="color: blue">Action</span><span style="color: gray">=</span><span style="color: red">&quot;setValue&quot;
  </span>ElementPath<span style="color: gray">=</span><span style="color: red">&quot;//configuration/appSettings/add[[]@key=’MySetting’[]]/@value&quot;
  </span>Value<span style="color: gray">=</span><span style="color: red">&quot;[TARGETVALUE]&quot; </span><span style="color: gray">/&gt;
&lt;/</span>Component<span style="color: gray">&gt;</span></pre>
<p>Note that we need to escape the square brackets in XPATH to the element.</p>
<p>&#160;</p>
<p>Hope it helps.</p>
<p>- Ranjith</p>
]]></content:encoded>
			<wfw:commentRss>http://ranjithk.com/2009/11/06/wix-update-application-configuration-files-during-installation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

