<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4971377397859266634</id><updated>2012-02-16T13:38:45.051-05:00</updated><category term='sql2005'/><category term='C#'/><category term='LINQ'/><category term='sharepoint'/><category term='XML'/><category term='Continuous Integration'/><category term='aspnet20'/><category term='PFX'/><category term='SQL2000'/><title type='text'>Keeping up with Microsoft.</title><subtitle type='html'>Blogs on code snippets and tools that every &lt;a href="http://bit.ly/rbgcv"&gt;.NET&lt;/a&gt; developer would need to have on fingerTips...</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>74</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-4438447017497375229</id><published>2011-02-16T13:33:00.001-05:00</published><updated>2011-02-16T13:33:44.437-05:00</updated><title type='text'>Site Web Analytics not updating Sharepoint 2010</title><content type='html'>&lt;p&gt;If you facing the issue that the web Analytics Reports in Sharepoint 2010 Central Administration is not updating data.   &lt;br /&gt;    &lt;br /&gt;When you go to your site &amp;gt; site settings &amp;gt; Site Web Analytics reports or Site Collection Analytics reports&amp;#160; &lt;br /&gt;You get old data as in the ribbon displayed &amp;quot;Data Last Updated: 12/13/2010 2:00:20 AM&amp;quot;&lt;/p&gt;  &lt;p&gt;Please insure that the following things are covered:   &lt;br /&gt;Insure that &lt;strong&gt;Usage and Data Health Data Collection&lt;/strong&gt; service is configured correctly.     &lt;br /&gt;&lt;strong&gt;Log Collection Schedule&lt;/strong&gt; is configured correctly    &lt;br /&gt;&lt;strong&gt;Microsoft Sharepoint Foundation Usage Data Import&lt;/strong&gt; and &lt;a href="http://la-p-sharept01:5555/_admin/JobEdit.aspx?JobId=36c67278%2D6c69%2D4c81%2Da1fb%2D4eb51c2672a8&amp;amp;Source=%2F%5Fadmin%2FServiceJobDefinitions%2Easpx"&gt;Microsoft SharePoint Foundation Usage Data Processing&lt;/a&gt; Timer jobs are configured to run at regular intervals    &lt;br /&gt;One last important Timer job is the &lt;a href="http://la-p-sharept01:5555/_admin/JobEdit.aspx?JobId=2daaa629%2De20b%2D4fd7%2D917e%2D5224f47c603c&amp;amp;Source=%2F%5Fadmin%2FServiceJobDefinitions%2Easpx%3FPageIndex%3D1"&gt;Web Analytics Trigger Workflows Timer Job&lt;/a&gt; insure that this timer job is enabled and scheduled to run at regular intervals (for each site that you need analytics for).    &lt;br /&gt;After you have insured that the web analytics service configuration is working fine and the Usage Data Import job is importing the *.usage files from the ULS LOGS folder into the WSS_Logging database, and that all the required timer jobs are running as expected… &lt;strong&gt;wait for a day&lt;/strong&gt; for the report to get updated… the report gets updated automatically at 2:00 am in the morning… and i could not find a way to control the schedule for this report update job.    &lt;br /&gt;    &lt;br /&gt;So be sure to wait for a day before giving up :)&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-4438447017497375229?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/4438447017497375229/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=4438447017497375229' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/4438447017497375229'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/4438447017497375229'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2011/02/site-web-analytics-not-updating.html' title='Site Web Analytics not updating Sharepoint 2010'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-8998704954087497301</id><published>2011-02-04T17:52:00.001-05:00</published><updated>2011-02-16T13:41:32.140-05:00</updated><title type='text'>Change AccountName/LoginName for a SharePoint User (SPUser)</title><content type='html'>&lt;p&gt;Consider the following:    &lt;br /&gt;We have an account named &lt;b&gt;MYDOMAIN\eholz&lt;/b&gt;. This accounts Active Directory Login Name changes to &lt;strong&gt;MYDOMAIN\eburrell      &lt;br /&gt;&lt;/strong&gt;Now this user was a active user in a Sharepoint 2010 team Site, and had a userProfile using the Account name MYDOMAIN\eholz.     &lt;br /&gt;Since the AD LoginName changed to eburrell hence we need to update the Sharepoint User (SPUser object) as well update the userprofile to reflect the new account name.     &lt;br /&gt;To update the Sharepoint User LoginName we can run the following stsadm command on the Server:     &lt;br /&gt;    &lt;br /&gt;&lt;strong&gt;STSADM –o migrateuser –oldlogin MYDOMAIN\eholz –newlogin MYDOMAIN\eburrell –ignoresidhistory&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;However to update the Sharepoint 2010 UserProfile, i first tried running a Incremental/Full Synchronization using the User Profile Synchronization service… this did not work. To enable me to update the AccountName field (which is a read only field) of the UserProfile, I had to first delete the User Profile for MYDOMAIN\eholz and then run a FULL Synchronization using the User Profile Synchronization service which synchronizes the Sharepoint User Profiles with the AD profiles.&lt;/p&gt;  &lt;p&gt;Update: if you just run the STSADM –o migrateuser command… the profile also gets updated automatically. so all you need is to run the stsadm –o migrate user command and you dont need to delete and recreate the User Profile&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-8998704954087497301?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/8998704954087497301/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=8998704954087497301' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/8998704954087497301'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/8998704954087497301'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2011/02/change-accountnameloginname-for.html' title='Change AccountName/LoginName for a SharePoint User (SPUser)'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-282017742525464536</id><published>2010-06-18T12:51:00.001-04:00</published><updated>2010-06-18T12:51:23.857-04:00</updated><title type='text'>Search All Columns in All Tables using TSQL</title><content type='html'>&lt;pre class="cpp" ?="?" name="code"&gt;DECLARE @SearchStr nvarchar(100)&lt;br /&gt;&lt;br /&gt;SET @SearchStr = 'SEARCH_KEYWORD'&lt;br /&gt;&lt;br /&gt;CREATE TABLE #Results (ColumnName nvarchar(370), ColumnValue nvarchar(3630))&lt;br /&gt;&lt;br /&gt;SET NOCOUNT ON&lt;br /&gt;&lt;br /&gt;DECLARE @TableName nvarchar(256), @ColumnName nvarchar(128), @SearchStr2 nvarchar(110)&lt;br /&gt;SET  @TableName = ''&lt;br /&gt;SET @SearchStr2 = QUOTENAME('%' + @SearchStr + '%','''')&lt;br /&gt;&lt;br /&gt;WHILE @TableName IS NOT NULL&lt;br /&gt;BEGIN&lt;br /&gt;	SET @ColumnName = ''&lt;br /&gt;	SET @TableName = &lt;br /&gt;	(&lt;br /&gt;		SELECT MIN(QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME))&lt;br /&gt;		FROM 	INFORMATION_SCHEMA.TABLES&lt;br /&gt;		WHERE 		TABLE_TYPE = 'BASE TABLE'&lt;br /&gt;			AND	QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME) &amp;gt; @TableName&lt;br /&gt;			AND	OBJECTPROPERTY(&lt;br /&gt;					OBJECT_ID(&lt;br /&gt;						QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME)&lt;br /&gt;						 ), 'IsMSShipped'&lt;br /&gt;					       ) = 0&lt;br /&gt;	)&lt;br /&gt;&lt;br /&gt;	WHILE (@TableName IS NOT NULL) AND (@ColumnName IS NOT NULL)&lt;br /&gt;	BEGIN&lt;br /&gt;		SET @ColumnName =&lt;br /&gt;		(&lt;br /&gt;			SELECT MIN(QUOTENAME(COLUMN_NAME))&lt;br /&gt;			FROM 	INFORMATION_SCHEMA.COLUMNS&lt;br /&gt;			WHERE 		TABLE_SCHEMA	= PARSENAME(@TableName, 2)&lt;br /&gt;				AND	TABLE_NAME	= PARSENAME(@TableName, 1)&lt;br /&gt;				AND	DATA_TYPE IN ('char', 'varchar', 'nchar', 'nvarchar')&lt;br /&gt;				AND	QUOTENAME(COLUMN_NAME) &amp;gt; @ColumnName&lt;br /&gt;		)&lt;br /&gt;&lt;br /&gt;		IF @ColumnName IS NOT NULL&lt;br /&gt;		BEGIN&lt;br /&gt;			INSERT INTO #Results&lt;br /&gt;			EXEC&lt;br /&gt;			(&lt;br /&gt;				'SELECT ''' + @TableName + '.' + @ColumnName + ''', LEFT(' + @ColumnName + ', 3630) &lt;br /&gt;				FROM ' + @TableName + ' (NOLOCK) ' +&lt;br /&gt;				' WHERE ' + @ColumnName + ' LIKE ' + @SearchStr2&lt;br /&gt;			)&lt;br /&gt;		END&lt;br /&gt;	END	&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;SELECT ColumnName, ColumnValue FROM #Results&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-282017742525464536?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/282017742525464536/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=282017742525464536' title='23 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/282017742525464536'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/282017742525464536'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2010/06/search-all-columns-in-all-tables-using.html' title='Search All Columns in All Tables using TSQL'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>23</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-899173764833653493</id><published>2010-06-07T18:54:00.001-04:00</published><updated>2010-06-07T19:05:48.535-04:00</updated><title type='text'>Unit testing internal methods in a strongly named assembly/project</title><content type='html'>&lt;p&gt;If you need create Unit tests for internal methods within a assembly in Visual Studio 2005 or greater, then we need to add an entry in the AssemblyInfo.cs file of the assembly for which you are creating the units tests for. For e.g. if you need to create tests for a assembly named FincadFunctions.dll &amp;amp; this assembly contains internal/friend methods within which need to write unit tests for then we add a entry in the FincadFunctions.dll’s AssemblyInfo.cs file like so : &lt;/p&gt;  &lt;pre class="cpp" ?="?" name="code"&gt;[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(&amp;quot;FincadFunctionsTests&amp;quot;)]&lt;/pre&gt;&lt;br /&gt;where FincadFunctionsTests is the name of the Unit Test project which contains the Unit Tests. However if the fincadFunctions.dll is a strongly named assembly then you will the following error when compiling the FincadFunctions.dll assembly : &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;u&gt;Friend assembly reference “FincadFunctionsTests” is invalid. Strong-name assemblies must specify a public key in their InternalsVisibleTo declarations. &lt;br /&gt;  &lt;br /&gt;&lt;/u&gt;Thus to add a public key token to InternalsVisibleTo Declarations do the following: You need the .snk file that was used to strong-name the FincadFunctions.dll assembly. You can extract the public key from this .snk with the sn.exe tool from the .NET SDK. First we extract just the public key from the key pair (.snk) file into another .snk file. &lt;u&gt;sn -p test.snk test.pub&lt;/u&gt; Then we ask for the value of that public key (note we need the long hex key not the short public key token): &lt;u&gt;sn -tp test.pub&lt;/u&gt; We end up getting a super LONG string of hex, but that's just what we want, the public key value of this key pair. We add it to the strongly named project &amp;quot;FincadFunctions.dll&amp;quot; that we want to expose our internals from. Before what looked like: &lt;br /&gt;&lt;br /&gt;&lt;pre class="cpp" ?="?" name="code"&gt;[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(&amp;quot;FincadFunctionsTests&amp;quot;)]&lt;/pre&gt;&lt;br /&gt;Now looks like. &lt;br /&gt;&lt;br /&gt;&lt;pre class="cpp" ?="?" name="code"&gt;[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(&amp;quot;FincadFunctionsTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010011fdf2e48bb&amp;quot;)]&lt;/pre&gt;&lt;br /&gt;And we're done. hope this helps &lt;br /&gt;&lt;br /&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-899173764833653493?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/899173764833653493/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=899173764833653493' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/899173764833653493'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/899173764833653493'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2010/06/unit-testing-internal-methods-in.html' title='Unit testing internal methods in a strongly named assembly/project'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-1255227718635356709</id><published>2010-05-21T19:40:00.001-04:00</published><updated>2010-05-21T20:00:53.922-04:00</updated><title type='text'>LinqToXML removing empty xmlns attributes</title><content type='html'>Suppose you need to generate the following XML:   &lt;pre class="cpp" ?="?" name="code"&gt;&amp;lt;GenevaLoader xmlns:xsi=&amp;quot;http://www.w3.org/2001/XMLSchema-instance&amp;quot; xsi:schemaLocation=&amp;quot;http://www.advent.com/SchemaRevLevel401/Geneva masterschema.xsd&amp;quot; xmlns=&amp;quot;http://www.advent.com/SchemaRevLevel401/Geneva&amp;quot;&amp;gt;&lt;br /&gt;  &amp;lt;PriceRecords&amp;gt;&lt;br /&gt;    &amp;lt;PriceRecord&amp;gt;&lt;br /&gt;    &amp;lt;/PriceRecord&amp;gt;&lt;br /&gt;  &amp;lt;/PriceRecords&amp;gt;&lt;br /&gt;&amp;lt;/GenevaLoader&amp;gt;&lt;/pre&gt;&lt;br /&gt;Normally you would write the following C# code to accomplish this: &lt;br /&gt;&lt;br /&gt;&lt;pre class="cpp" ?="?" name="code"&gt;const string ns = &amp;quot;http://www.advent.com/SchemaRevLevel401/Geneva&amp;quot;;&lt;br /&gt;XNamespace xnsp = ns;&lt;br /&gt;XNamespace xsi = XNamespace.Get(&amp;quot;http://www.w3.org/2001/XMLSchema-instance&amp;quot;);&lt;br /&gt;&lt;br /&gt;XElement root = new XElement( xnsp + &amp;quot;GenevaLoader&amp;quot;,  &lt;br /&gt;  new XAttribute(XNamespace.Xmlns + &amp;quot;xsi&amp;quot;, xsi.NamespaceName), &lt;br /&gt;  new XAttribute( xsi + &amp;quot;schemaLocation&amp;quot;, &amp;quot;http://www.advent.com/SchemaRevLevel401/Geneva masterschema.xsd&amp;quot;));&lt;br /&gt;&lt;br /&gt;XElement priceRecords = new XElement(&amp;quot;PriceRecords&amp;quot;);&lt;br /&gt;root.Add(priceRecords);&lt;br /&gt;&lt;br /&gt;	for(int i = 0; i &amp;lt; 3; i++)&lt;br /&gt;	{&lt;br /&gt;	    XElement price = new XElement(&amp;quot;PriceRecord&amp;quot;);&lt;br /&gt;	   priceRecords.Add(price);&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;	doc.Save(&amp;quot;geneva.xml&amp;quot;);&lt;/pre&gt;&lt;br /&gt;The problem with this approach is that it adds a additional empty xmlns arrtribute on the “PriceRecords” element, like so : &lt;br /&gt;&lt;br /&gt;&lt;pre class="cpp" ?="?" name="code"&gt;&amp;lt;GenevaLoader xmlns:xsi=&amp;quot;http://www.w3.org/2001/XMLSchema-instance&amp;quot; xsi:schemaLocation=&amp;quot;http://www.advent.com/SchemaRevLevel401/Geneva masterschema.xsd&amp;quot; xmlns=&amp;quot;http://www.advent.com/SchemaRevLevel401/Geneva&amp;quot;&amp;gt;&lt;br /&gt;  &amp;lt;PriceRecords xmlns=&amp;quot;&amp;quot;&amp;gt;&lt;br /&gt;    &amp;lt;PriceRecord&amp;gt;&lt;br /&gt;    &amp;lt;/PriceRecord&amp;gt;&lt;br /&gt;  &amp;lt;/PriceRecords&amp;gt;&lt;br /&gt;&amp;lt;/GenevaLoader&amp;gt;&lt;/pre&gt;&lt;br /&gt;The solution is to add the xmlns NameSpace in code to each child and grandchild elements of the root element like so : &lt;br /&gt;&lt;br /&gt;&lt;pre class="cpp" ?="?" name="code"&gt;XElement priceRecords = new XElement( xnsp + &amp;quot;PriceRecords&amp;quot;);&lt;br /&gt;root.Add(priceRecords);&lt;br /&gt;&lt;br /&gt;for(int i = 0; i &amp;lt; 3; i++)&lt;br /&gt;{&lt;br /&gt;    XElement price = new XElement(xnsp + &amp;quot;PriceRecord&amp;quot;);&lt;br /&gt;   priceRecords.Add(price);&lt;br /&gt;}&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-1255227718635356709?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/1255227718635356709/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=1255227718635356709' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/1255227718635356709'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/1255227718635356709'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2010/05/linqtoxml-removing-empty-xmlns.html' title='LinqToXML removing empty xmlns attributes'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-6646869720609662987</id><published>2010-05-21T18:46:00.001-04:00</published><updated>2010-05-21T18:46:03.451-04:00</updated><title type='text'>Copying files from GAC using xcopy or Windows Explorer</title><content type='html'>&lt;p&gt;use this command for copying files using a wildcard from the GAC to a local folder.    &lt;br /&gt;xcopy c:\windows\assembly\Microsoft.SqlServer.Smo*.dll c:\gacdll /s/r/y/c     &lt;br /&gt;    &lt;br /&gt;The above command will continue even it encounters any “Access Denied” errors, thus copying over the required files.     &lt;br /&gt;    &lt;br /&gt;To copy files using the Windows explorer just disable the GAC Cache Viewer by adding a entry to the registry:     &lt;br /&gt;Browse to &lt;strong&gt;“HKEY_LOCALMACHINE\Software\Microsoft\Fusion”      &lt;br /&gt;&lt;/strong&gt;Add a Dword called &lt;strong&gt;DisableCacheViewer&lt;/strong&gt;. Set the value of it to &lt;strong&gt;1&lt;/strong&gt;.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-6646869720609662987?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/6646869720609662987/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=6646869720609662987' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/6646869720609662987'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/6646869720609662987'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2010/05/copying-files-from-gac-using-xcopy-or.html' title='Copying files from GAC using xcopy or Windows Explorer'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-4049457182203621155</id><published>2010-05-11T18:50:00.001-04:00</published><updated>2010-05-11T19:05:30.992-04:00</updated><title type='text'>Entity Framework v1 – tips and Tricks Part 3</title><content type='html'>&lt;h5&gt;   &lt;br /&gt;&lt;/h5&gt;  &lt;p&gt;The previous posts on Entity framework are available here :    &lt;br /&gt;&lt;a href="http://geekswithblogs.net/rgupta/archive/2010/04/01/entity-framework-version-1---brief-synopsis-and-tips-ndash.aspx"&gt;Entity Framework version 1- Brief Synopsis and Tips – Part 1&lt;/a&gt;     &lt;br /&gt;&lt;a href="http://geekswithblogs.net/rgupta/archive/2010/04/13/entity-framework-v1-hellip-brief-synopsis-and-tips-ndash-part.aspx"&gt;Entity Framework v1 … Brief Synopsis and Tips – Part 2&lt;/a&gt;     &lt;br /&gt;    &lt;br /&gt;&lt;strong&gt;&lt;u&gt;General Tips on Entity Framework v1 &amp;amp; Linq to Entities: &lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;ToTraceString()&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;If you need to know the underlying SQL that the EF generates for a Linq To Entities query, then use the ToTraceString() method of the ObjectQuery class. (or use &lt;strong&gt;&lt;u&gt;LINQPAD&lt;/u&gt;&lt;/strong&gt;)     &lt;br /&gt;Note that you need to cast the LINQToEntities query to ObjectQuery before calling TotraceString() as follows:&lt;/p&gt;  &lt;pre class="cpp" ?="?" name="code"&gt;string efSQL = ((ObjectQuery)from c in ctx.Contact&lt;br /&gt;         where c.Address.Any(a =&amp;gt; a.CountryRegion == &amp;quot;US&amp;quot;)&lt;br /&gt;         select c.ContactID).ToTraceString();&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;======================================================================&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;MARS or MultipleActiveResultSet &lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;When you create a EDM Model (EDMX file) from the database using Visual Studio, it generates a connection string with the same name as the name of the EntityContainer in CSDL. In the ConnectionString so generated it sets the MultipleActiveResultSet attribute to true by default. So if you are running the following query then it streams multiple readers over the same connection:&lt;br /&gt;&lt;br /&gt;&lt;pre class="cpp" ?="?" name="code"&gt;using (BAEntities context = new BAEntities())&lt;br /&gt;{&lt;br /&gt;  var cons =&lt;br /&gt;      from con in context.Contacts&lt;br /&gt;      where con.FirstName == &amp;quot;Jose&amp;quot;&lt;br /&gt;      select con;&lt;br /&gt;  foreach (var c in cons)&lt;br /&gt;  {&lt;br /&gt;    if (c.AddDate &amp;lt; new System.DateTime(2007, 1, 1))&lt;br /&gt;    {&lt;br /&gt;      c.Addresses.Load();&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;}&lt;/pre&gt;====================================================================== &lt;br /&gt;&lt;strong&gt;&lt;u&gt;Explicitly opening and closing EntityConnection&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;When you call ToList() or foreach on a LINQToEntities query the EF automatically closes the connection after all the records from the query have been consumed. &lt;br /&gt;  &lt;br /&gt;Thus if you need to run many LINQToEntities queries over the same connection then explicitly open and close the connection as follows:&lt;pre class="cpp" ?="?" name="code"&gt;using (BAEntities context = new BAEntities())&lt;br /&gt;{&lt;br /&gt;  context.Connection.Open();&lt;br /&gt;  var cons = from con in context.Contacts where con.FirstName == &amp;quot;Jose&amp;quot;&lt;br /&gt;             select con;&lt;br /&gt;  var conList = cons.ToList();&lt;br /&gt;  var allCustomers =  from con in context.Contacts.OfType&amp;lt;Customer&amp;gt;()&lt;br /&gt;                      select con;&lt;br /&gt;  var allcustList = allCustomers.ToList();&lt;br /&gt;  context.Connection.Close();&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;====================================================================== &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;&lt;u&gt;Dispose ObjectContext only if required &lt;br /&gt;      &lt;br /&gt;&lt;/u&gt;&lt;/strong&gt;After you retrieve entities using the ObjectContext and you are not explicitly disposing the ObjectContext then insure that your code &lt;strong&gt;&lt;u&gt;does&lt;/u&gt;&lt;/strong&gt; consume all the records from the LinqToEntities query by calling .ToList() or foreach statement, otherwise the the database connection will remain open and will be closed by the garbage collector when it gets to dispose the ObjectContext. &lt;br /&gt;  &lt;br /&gt;Secondly if you are making updates to the entities retrieved using LinqToEntities then insure that you dont inadverdently dispose of the ObjectContext after the entities are retrieved and before calling .SaveChanges() since you need the SAME ObjectContext to keep track of changes made to the Entities (by using ObjectStateEntry objects). So if you do need to explicitly dispose of the ObjectContext do so only after calling SaveChanges() and only if you &lt;strong&gt;&lt;u&gt;dont &lt;/u&gt;&lt;/strong&gt;need to change track the entities retrieved any further. &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;======================================================================&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;SQL InjectionAttacks under control with EFv1 &lt;br /&gt;      &lt;br /&gt;&lt;/u&gt;&lt;/strong&gt;LinqToEntities and LinqToSQL queries are parameterized before they are sent to the DB hence they are not vulnerable to SQL Injection attacks. &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;EntitySQL may be slightly vulnerable to attacks since it does not use parameterized queries. However since the EntitySQL demands that the query be valid Entity SQL syntax and valid native SQL syntax at the same time. &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;So the only way one can do a SQLInjection Attack is by knowing the SSDL of the EDM Model and be able to write the correct EntitySQL (note one cannot append regular SQL since then the query wont be a valid EntitySQL syntax) and append it to a parameter. &lt;br /&gt;&lt;br /&gt;====================================================================== &lt;br /&gt;&lt;strong&gt;&lt;u&gt;Improving Performance&lt;br /&gt;&lt;/u&gt;&lt;/strong&gt;You can convert the EntitySets and AssociationSets in a EDM Model into precompiled Views using the edmgen utility. for e.g. the Customer Entity can be converted into a precompiled view using edmgen and all LinqToEntities query against the contaxt.Customer EntitySet will use the precompiled View instead of the EntitySet itself (the same being true for relationships (EntityReference &amp;amp; EntityCollections of a Entity)). The advantage being that when using precompiled views the performance will be much better. &lt;br /&gt;  &lt;br /&gt;The syntax for generating precompiled views for a existing EF project is : &lt;br /&gt;&lt;u&gt;edmgen /mode:ViewGeneration /inssdl:BAModel.ssdl /incsdl:BAModel.csdl /inmsl:BAModel.msl /p:Chap14.csproj &lt;br /&gt;&lt;/u&gt;Note that this will only generate precompiled views for EntitySets and Associations and not for existing LinqToEntities queries in the project.(for that use CompiledQuery.Compile&amp;lt;&amp;gt;) &lt;br /&gt;Secondly if you have a LinqToEntities query that you need to &lt;strong&gt;&lt;u&gt;run multiple times&lt;/u&gt;&lt;/strong&gt;, then one should precompile the query using CompiledQuery.Compile method. The CompiledQuery.Compile&amp;lt;&amp;gt; method accepts a lamda expression as a parameter, which denotes the LinqToEntities query&amp;#160; that you need to precompile. &lt;br /&gt;&lt;br /&gt;The following is a example of a lamda that we can pass into the CompiledQuery.Compile() method&lt;br /&gt;&lt;pre class="cpp" ?="?" name="code"&gt;Expression&amp;lt;Func&amp;lt;BAEntities, string, IQueryable&amp;lt;Customer&amp;gt;&amp;gt;&amp;gt; expr = (BAEntities ctx1, string loc) =&amp;gt;&lt;br /&gt;                    from c in ctx1.Contacts.OfType&amp;lt;Customer&amp;gt;()&lt;br /&gt;                    where c.Reservations.Any(r =&amp;gt; r.Trip.Destination.DestinationName == loc)&lt;br /&gt;                    select c;&lt;/pre&gt;Then we call the Compiled Query as follows:&lt;br /&gt;&lt;pre class="cpp" ?="?" name="code"&gt;var query = CompiledQuery.Compile&amp;lt;BAEntities, string, IQueryable&amp;lt;Customer&amp;gt;&amp;gt;(expr);&lt;br /&gt;&lt;br /&gt;using (BAEntities ctx = new BAEntities())&lt;br /&gt;{&lt;br /&gt;    var loc = &amp;quot;Malta&amp;quot;;&lt;br /&gt;    IQueryable&amp;lt;Customer&amp;gt; custs = query.Invoke(ctx, loc);&lt;br /&gt;    var custlist = custs.ToList();&lt;br /&gt;    foreach (var item in custlist)&lt;br /&gt;    {&lt;br /&gt;        Console.WriteLine(item.FullName);&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;Note that if you created a ObjectQuery or a Enitity SQL query instead of the LINQToEntities query, you dont need precompilation for e.g.&lt;pre class="cpp" ?="?" name="code"&gt;An Example of EntitySQL query :&lt;br /&gt;string esql = &amp;quot;SELECT VALUE c from Contacts AS c where c is of(BAGA.Customer) and c.LastName = 'Gupta'&amp;quot;;&lt;br /&gt;ObjectQuery&amp;lt;Customer&amp;gt; custs = CreateQuery&amp;lt;Customer&amp;gt;(esql);&lt;br /&gt;&lt;br /&gt;An Example of ObjectQuery built using ObjectBuilder methods:&lt;br /&gt;from c in Contacts.OfType&amp;lt;Customer&amp;gt;().Where(&amp;quot;it.LastName == 'Gupta'&amp;quot;)&lt;br /&gt;select c&lt;/pre&gt;&lt;br /&gt;This is since the Query plan is cached and thus the performance improves a bit, however since the ObjectQuery or EntitySQL query still needs to materialize the results into Entities hence it will take the same amount of performance hit as with LinqToEntities. &lt;br /&gt;  &lt;br /&gt;However note that &lt;strong&gt;&lt;u&gt;not&lt;/u&gt;&lt;/strong&gt; ALL EntitySQL based or QueryBuilder based ObjectQuery plans are cached. So if you are in doubt always create a LinqToEntities compiled query and use that instead &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;============================================================ &lt;br /&gt;&lt;strong&gt;&lt;u&gt;GetObjectStateEntry Versus GetObjectByKey &lt;br /&gt;      &lt;br /&gt;&lt;/u&gt;&lt;/strong&gt;We can get to the Entity being referenced by the ObjectStateEntry via its Entity property and there are helper methods in the ObjectStateManager (osm.TryGetObjectStateEntry) to get the ObjectStateEntry for a entity (for which we know the EntityKey). Similarly The ObjectContext has helper methods to get an Entity i.e. TryGetObjectByKey(). &lt;br /&gt;&lt;br /&gt;TryGetObjectByKey() uses &lt;tt&gt;GetObjectStateEntry&lt;/tt&gt;&lt;a name="the"&gt;&lt;/a&gt; method under the covers to find the object, however One important difference between these 2 methods is that &lt;tt&gt;TryGetObjectByKey&lt;/tt&gt;&lt;a name="if it"&gt;&lt;/a&gt; queries the database if it is unable to find the object in the context, whereas &lt;tt&gt;TryGetObjectStateEntry&lt;/tt&gt;&lt;a name="in the"&gt;&lt;/a&gt; only looks in the context for existing entries. It will not make a trip to the database&lt;br /&gt;============================================================= &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;&lt;u&gt;POCO objects with EFv1:&lt;/u&gt;&lt;/strong&gt; &lt;br /&gt;To create POCO objects that can be used with EFv1. We need to implement 3 key interfaces: &lt;br /&gt;&lt;br /&gt;IEntityWithKey &lt;br /&gt;IEntityWithRelationships &lt;br /&gt;IEntityWithChangeTracker &lt;br /&gt;  &lt;br /&gt;Implementing IEntityWithKey is not mandatory, but if you dont then we need to explicitly provide values for the EntityKey for various functions (for e.g. the functions needed to implement IEntityWithChangeTracker and IEntityWithRelationships). &lt;br /&gt;&lt;br /&gt;Implementation of IEntityWithKey involves exposing a property named EntityKey which returns a EntityKey object. &lt;br /&gt;Implementation of IEntityWithChangeTracker involves implementing a method named SetChangeTracker since there can be multiple changetrackers (Object Contexts) existing in memory at the same time.&lt;br /&gt;&lt;pre class="cpp" ?="?" name="code"&gt;public void SetChangeTracker(IEntityChangeTracker changeTracker)&lt;br /&gt;{&lt;br /&gt;  _changeTracker = changeTracker;&lt;br /&gt;}&lt;/pre&gt;Additionally each property in the POCO object needs to notify the changetracker (objContext) that it is updating itself by calling the &lt;tt&gt;EntityMemberChanged&lt;/tt&gt; and &lt;tt&gt;EntityMemberChanging&lt;/tt&gt; methods on the changeTracker. for e.g.:&lt;br /&gt;&lt;br /&gt;&lt;pre class="cpp" ?="?" name="code"&gt;public EntityKey EntityKey&lt;br /&gt;{&lt;br /&gt;  get { return _entityKey; }&lt;br /&gt;  set&lt;br /&gt;  {&lt;br /&gt;    if (_changeTracker != null)&lt;br /&gt;    {&lt;br /&gt;       _changeTracker.EntityMemberChanging(&amp;quot;EntityKey&amp;quot;);&lt;br /&gt;       _entityKey = value;&lt;br /&gt;       _changeTracker.EntityMemberChanged(&amp;quot;EntityKey&amp;quot;);&lt;br /&gt;     }&lt;br /&gt;     else&lt;br /&gt;       _entityKey = value;&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;=====================  Custom Property  ====================================&lt;br /&gt;&lt;br /&gt;[EdmScalarPropertyAttribute(IsNullable = false)]&lt;br /&gt;public System.DateTime OrderDate&lt;br /&gt;{&lt;br /&gt;  get { return _orderDate; }&lt;br /&gt;  set&lt;br /&gt;  {&lt;br /&gt;    if (_changeTracker != null)&lt;br /&gt;    {&lt;br /&gt;      _changeTracker.EntityMemberChanging(&amp;quot;OrderDate&amp;quot;);&lt;br /&gt;      _orderDate = value;&lt;br /&gt;      _changeTracker.EntityMemberChanged(&amp;quot;OrderDate&amp;quot;);&lt;br /&gt;    }&lt;br /&gt;    else&lt;br /&gt;      _orderDate = value;&lt;br /&gt;  }&lt;br /&gt;}&lt;/pre&gt;Finally you also need to create the EntityState property as follows:&lt;br /&gt;&lt;br /&gt;&lt;pre class="cpp" ?="?" name="code"&gt;public EntityState EntityState&lt;br /&gt;{&lt;br /&gt;  get  { return _changeTracker.EntityState;  }&lt;br /&gt;}&lt;/pre&gt;The IEntityWithRelationships involves creating a property that returns RelationshipManager object:&lt;br /&gt;&lt;pre class="cpp" ?="?" name="code"&gt;public RelationshipManager RelationshipManager&lt;br /&gt;{&lt;br /&gt;  get&lt;br /&gt;  {&lt;br /&gt;    if (_relManager == null)&lt;br /&gt;      _relManager = RelationshipManager.Create(this);&lt;br /&gt;    return _relManager;&lt;br /&gt;  }&lt;br /&gt;}&lt;/pre&gt;============================================================ &lt;br /&gt;  &lt;br /&gt;&lt;strong&gt;&lt;u&gt;Tip : ProviderManifestToken – change EDMX File to use SQL 2008 instead of SQL 2005 &lt;br /&gt;      &lt;br /&gt;&lt;/u&gt;&lt;/strong&gt;To use with SQL Server 2008, edit the EDMX file (the raw XML) changing the ProviderManifestToken in the SSDL attributes from &amp;quot;2005&amp;quot; to &amp;quot;2008&amp;quot; &lt;br /&gt;============================================================= &lt;br /&gt;With EFv1 we cannot use Structs to replace a anonymous Type while doing projections in a LINQ to Entities query. While the same is supported with LINQToSQL, it is not with LinqToEntities. For e.g. the following is &lt;strong&gt;&lt;u&gt;not&lt;/u&gt;&lt;/strong&gt; supported with LinqToEntities since only parameterless constructors and initializers are supported in LINQ to Entities. (the same works with LINQToSQL)&lt;br /&gt;&lt;br /&gt;&lt;pre class="cpp" ?="?" name="code"&gt;public struct CompanyInfo&lt;br /&gt;{&lt;br /&gt;    public int ID { get; set; }&lt;br /&gt;    public string Name { get; set; }&lt;br /&gt;}&lt;br /&gt;var companies = (from c in dc.Companies&lt;br /&gt;            where c.CompanyIcon == null&lt;br /&gt;             select new CompanyInfo { Name = c.CompanyName, ID = c.CompanyId }).ToList(); ;&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-4049457182203621155?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/4049457182203621155/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=4049457182203621155' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/4049457182203621155'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/4049457182203621155'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2010/05/entity-framework-v1-tips-and-tricks_11.html' title='Entity Framework v1 – tips and Tricks Part 3'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-8813088957843158621</id><published>2009-12-14T16:57:00.002-05:00</published><updated>2009-12-14T17:00:14.550-05:00</updated><title type='text'>Split SQL 2005 column values into multiple rows</title><content type='html'>&lt;p&gt;Suppose that you have a column that stored multiple values in a single row using some delimiter as ‘,’.  Now you are tasked with splitting these values into a separate row for each value and you need to do this on multiple rows in the table. &lt;/p&gt;&lt;div id="codeSnippetWrapper"&gt;&lt;div style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; DIRECTION: ltr; BORDER-TOP-STYLE: none; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:black;" id="codeSnippet"   &gt;&lt;pre style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: white; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; DIRECTION: ltr; BORDER-TOP-STYLE: none; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:black;"   &gt;&lt;span id="lnum1"  style="color:#606060;"&gt;   1:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;select&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;distinct&lt;/span&gt; r.items&lt;/pre&gt;&lt;pre style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; DIRECTION: ltr; BORDER-TOP-STYLE: none; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:black;"   &gt;&lt;span id="lnum2"  style="color:#606060;"&gt;   2:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;from&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;Order&lt;/span&gt; o&lt;/pre&gt;&lt;pre style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: white; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; DIRECTION: ltr; BORDER-TOP-STYLE: none; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:black;"   &gt;&lt;span id="lnum3"  style="color:#606060;"&gt;   3:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;cross&lt;/span&gt; apply dbo.split(o.Products,&lt;span style="color:#006080;"&gt;','&lt;/span&gt;) r&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;Here the Order Table has a Products column that has multiple Products stored in a single column separated with commas like ‘Tea,Coffee’ associated with a single Order. What the above query does is it gives a distinct list of names of all Products stored in all rows in the Order table. The Split() is a UDF which splits the string into one row for each value&lt;/p&gt;&lt;p&gt;Similarly if you need to check if these multiple values stored in the Products column contain a particular string from a list of values, i,e,&lt;/p&gt;&lt;div id="codeSnippetWrapper"&gt;&lt;div style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; DIRECTION: ltr; BORDER-TOP-STYLE: none; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:black;" id="codeSnippet"   &gt;&lt;br /&gt;&lt;pre style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: white; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; DIRECTION: ltr; BORDER-TOP-STYLE: none; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:black;"   &gt;&lt;span id="lnum1"  style="color:#606060;"&gt;   1:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;select&lt;/span&gt; o.* &lt;span style="color:#0000ff;"&gt;from&lt;/span&gt; Company c&lt;/pre&gt;&lt;pre style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; DIRECTION: ltr; BORDER-TOP-STYLE: none; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:black;"   &gt;&lt;span id="lnum2"  style="color:#606060;"&gt;   2:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;join&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;Order&lt;/span&gt; o &lt;span style="color:#0000ff;"&gt;on&lt;/span&gt; c.ItemID = o.companyItemID&lt;/pre&gt;&lt;pre style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: white; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; DIRECTION: ltr; BORDER-TOP-STYLE: none; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:black;"   &gt;&lt;span id="lnum3"  style="color:#606060;"&gt;   3:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;where&lt;/span&gt; (&lt;span style="color:#0000ff;"&gt;select&lt;/span&gt; * &lt;span style="color:#0000ff;"&gt;from&lt;/span&gt; dbo.split(o.Products) &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; (&lt;span style="color:#006080;"&gt;'TBD'&lt;/span&gt;,&lt;span style="color:#006080;"&gt;'Tea'&lt;/span&gt;, &lt;span style="color:#006080;"&gt;'Coffee'&lt;/span&gt;))&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;Since the above would not compile hence the right solution to do something like this would be:&lt;/p&gt;&lt;div id="codeSnippetWrapper"&gt;&lt;div style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; DIRECTION: ltr; BORDER-TOP-STYLE: none; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:black;" id="codeSnippet"   &gt;&lt;br /&gt;&lt;pre style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: white; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; DIRECTION: ltr; BORDER-TOP-STYLE: none; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:black;"   &gt;&lt;span id="lnum1"  style="color:#606060;"&gt;   1:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;select&lt;/span&gt; o.* &lt;span style="color:#0000ff;"&gt;from&lt;/span&gt; Company c&lt;/pre&gt;&lt;pre style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; DIRECTION: ltr; BORDER-TOP-STYLE: none; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:black;"   &gt;&lt;span id="lnum2"  style="color:#606060;"&gt;   2:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;join&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;Order&lt;/span&gt; o &lt;span style="color:#0000ff;"&gt;on&lt;/span&gt; c.ItemID = o.companyItemID&lt;/pre&gt;&lt;pre style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: white; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; DIRECTION: ltr; BORDER-TOP-STYLE: none; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:black;"   &gt;&lt;span id="lnum3"  style="color:#606060;"&gt;   3:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;cross&lt;/span&gt; apply dbo.Split(Products,&lt;span style="color:#006080;"&gt;','&lt;/span&gt;) p &lt;/pre&gt;&lt;pre style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; DIRECTION: ltr; BORDER-TOP-STYLE: none; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0pxfont-family:'Courier New', courier, monospace;font-size:8pt;color:black;"   &gt;&lt;span id="lnum4"  style="color:#606060;"&gt;   4:&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;where&lt;/span&gt; p.Items &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; (&lt;span style="color:#006080;"&gt;'TBD'&lt;/span&gt;,&lt;span style="color:#006080;"&gt;'Tea'&lt;/span&gt;,&lt;span style="color:#006080;"&gt;'Coffee'&lt;/span&gt;)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;what we are doing here is a inner join on the Split() table valued UDF which returns a table containing one row for each value split and then comparing each Item to see if it matches one of the product names i.e. Tea or Coffee.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-8813088957843158621?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/8813088957843158621/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=8813088957843158621' title='11 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/8813088957843158621'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/8813088957843158621'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2009/12/split-sql-2005-column-values-into.html' title='Split SQL 2005 column values into multiple rows'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>11</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-2169214838465405114</id><published>2009-03-06T17:32:00.001-05:00</published><updated>2009-03-06T17:32:41.694-05:00</updated><title type='text'>Dispose and Finalize methods and .NET Memory optimizations</title><content type='html'>&lt;p&gt;I have jotted down a few points on implementing the IDisposable and Finalize patterns in .NET.&lt;/p&gt;  &lt;p&gt;Please find it here : &lt;a target="_blank" href="http://geekswithblogs.net/rgupta/archive/2009/03/06/dispose-and-finalize-methods.aspx"&gt;Dispose and Finalize methods&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;I also jotted down some .net Memory Optimization tips: Please find them here : &lt;a target="_blank" href="http://geekswithblogs.net/rgupta/archive/2009/03/06/some-tips-on-.net-memory-usage.aspx"&gt;Some Tips on .NET Memory optimizations&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-2169214838465405114?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/2169214838465405114/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=2169214838465405114' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/2169214838465405114'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/2169214838465405114'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2009/03/dispose-and-finalize-methods-and-net.html' title='Dispose and Finalize methods and .NET Memory optimizations'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-4264128135865972160</id><published>2009-03-03T19:57:00.001-05:00</published><updated>2009-03-03T19:57:00.509-05:00</updated><title type='text'>Creating dynamically generated logfiles with log4net</title><content type='html'>&lt;p&gt;If you need to generate logfile names dynmically when using log4net then we can do this using the log4net Properties.&lt;/p&gt;  &lt;p&gt;To learn more on this please visit : &lt;a target="_blank" href="http://geekswithblogs.net/rgupta/archive/2009/03/03/dynamic-log-filenames-with-log4net.aspx"&gt;creating dynamic logfile names with log4net&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-4264128135865972160?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/4264128135865972160/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=4264128135865972160' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/4264128135865972160'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/4264128135865972160'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2009/03/creating-dynamically-generated-logfiles.html' title='Creating dynamically generated logfiles with log4net'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-1205303643478543223</id><published>2009-03-03T18:55:00.001-05:00</published><updated>2009-03-03T18:55:55.929-05:00</updated><title type='text'>Tips on using log4net RollingFileAppender</title><content type='html'>&lt;p&gt;I have compiled a list of useful properties that you can set on the RollingFileAppender in the log4net XML config file which can determine the order in which log file backups will be generated, whether they will rollover based on dates or size or both.&lt;/p&gt;  &lt;p&gt;For more information please check this link out : &lt;a target="_blank" href="http://geekswithblogs.net/rgupta/archive/2009/03/03/tips-on-using-log4net-rollingfileappender.aspx"&gt;Tips on using log4net RollingFileAppender&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-1205303643478543223?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/1205303643478543223/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=1205303643478543223' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/1205303643478543223'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/1205303643478543223'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2009/03/tips-on-using-log4net.html' title='Tips on using log4net RollingFileAppender'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-1827192027572300480</id><published>2009-01-28T20:06:00.002-05:00</published><updated>2010-05-11T17:48:25.945-04:00</updated><title type='text'>ConfigSectionHandler for Hierarchical configs</title><content type='html'>Here is a quick way to create a ConfigSection Handler for reading Hierarchical configs.  For e.g. suppose you need to read a config file which has the following structure:  &lt;pre name="code" class="cpp"&gt;&lt;br /&gt;&lt;mainconfig&gt;&lt;company&gt;MySpace&lt;/company&gt;&lt;br /&gt; &lt;subconfig&gt;&lt;br /&gt;  &lt;id&gt;23&lt;/id&gt;&lt;br /&gt;   &lt;firstname&gt;Rohit&lt;/firstname&gt;&lt;br /&gt;  &lt;lastname&gt;Gupta&lt;/lastname&gt;&lt;br /&gt;  &lt;/subconfig&gt;&lt;br /&gt;&lt;/mainconfig&gt;&lt;br /&gt;&lt;/pre&gt;For this you would create the 2 classes, one for the Parent Config and another for the chold config like this:&lt;br /&gt;&lt;pre name="code" class="cpp"&gt;&lt;br /&gt;  [XmlRoot("MainConfig")]&lt;br /&gt;   public class MainConfig&lt;br /&gt;   {&lt;br /&gt;       private static readonly MainConfig instance =&lt;br /&gt; (MainConfig)ConfigurationManager.GetSection("MainConfig");&lt;br /&gt;       public static MainConfig GetInstance()&lt;br /&gt;       {&lt;br /&gt;           if (instance == null)&lt;br /&gt;               throw new ConfigurationErrorsException(&lt;br /&gt;                   "Unable to locate or deserialize the 'MainConfig' section.");&lt;br /&gt;&lt;br /&gt;           return instance;&lt;br /&gt;       }&lt;br /&gt;&lt;br /&gt;       public string Company { get; set; }&lt;br /&gt;&lt;br /&gt;       public SubConfig FriendsConfig { get; set; }&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   [XmlRoot("SubConfig")]&lt;br /&gt;   public class SubConfig&lt;br /&gt;   {&lt;br /&gt;       public int ID { get; set; }&lt;br /&gt;       public string Name { get; set; }&lt;br /&gt;       public string LastName { get; set; }&lt;br /&gt;   }&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Then you would create a configsectionHandler class which reads the config from the .config file:&lt;br /&gt;&lt;pre name="code" class="cpp"&gt;&lt;br /&gt;&lt;br /&gt;public class MainConfigSectionHandler : IConfigurationSectionHandler&lt;br /&gt;   {&lt;br /&gt;       #region IConfigurationSectionHandler Members&lt;br /&gt;&lt;br /&gt;       public object Create(object parent, object configContext, System.Xml.XmlNode section)&lt;br /&gt;       {&lt;br /&gt;           MainConfig typedConfig = GetConfig&lt;mainconfig&gt;(section);&lt;br /&gt;&lt;br /&gt;           if (typedConfig != null)&lt;br /&gt;           {&lt;br /&gt;               #region Get Sub Configs&lt;br /&gt;               foreach (XmlNode node in section.ChildNodes)&lt;br /&gt;               {&lt;br /&gt;                   switch (node.Name)&lt;br /&gt;                   {&lt;br /&gt;                       case "SubConfig":&lt;br /&gt;                           SubConfig friendsConfig = GetConfig&lt;subconfig&gt;(node);&lt;br /&gt;                           typedConfig.FriendsConfig = friendsConfig;&lt;br /&gt;                           break;&lt;br /&gt;                       default:&lt;br /&gt;                           break;&lt;br /&gt;                   }&lt;br /&gt;               }&lt;br /&gt;               #endregion&lt;br /&gt;           }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;           return typedConfig;&lt;br /&gt;       }&lt;br /&gt;&lt;br /&gt;       public T GetConfig&lt;t&gt;(System.Xml.XmlNode section) where T : class&lt;br /&gt;       {&lt;br /&gt;           T sourcedObject = default(T);&lt;br /&gt;           Type t = typeof(T);&lt;br /&gt;           XmlSerializer ser = new XmlSerializer(typeof(T));&lt;br /&gt;           sourcedObject = ser.Deserialize(new XmlNodeReader(section)) as T;&lt;br /&gt;           return sourcedObject;&lt;br /&gt;       }&lt;br /&gt;&lt;br /&gt;       #endregion&lt;br /&gt;&lt;br /&gt;   }&lt;br /&gt;&lt;/t&gt;&lt;/subconfig&gt;&lt;/mainconfig&gt;&lt;/pre&gt;&lt;br /&gt;After this you would add a entry in the app.config for this configsection Handler as the following:&lt;br /&gt;&lt;pre name="code" class="cpp"&gt;&lt;br /&gt; &lt;configsections&gt;&lt;br /&gt;  &lt;section name="MainConfig" type="App.MainConfigSectionHandler,App"&gt;&lt;br /&gt; &lt;/section&gt;&lt;br /&gt;&lt;/configsections&gt;&lt;/pre&gt;&lt;br /&gt;Finally to read this config, you would write the following:&lt;br /&gt;&lt;pre name="code" class="cpp"&gt;&lt;br /&gt;MainConfig config = MainConfig.GetInstance(); Console.WriteLine(config.Company);&lt;br /&gt;Console.WriteLine(config.FriendsConfig.ID);&lt;br /&gt;Console.WriteLine(config.FriendsConfig.LastName);&lt;br /&gt;Console.WriteLine(config.FriendsConfig.Name);&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-1827192027572300480?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/1827192027572300480/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=1827192027572300480' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/1827192027572300480'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/1827192027572300480'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2009/01/configsectionhandler-for-hierarchical.html' title='ConfigSectionHandler for Hierarchical configs'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-4350966255596572413</id><published>2009-01-07T21:45:00.004-05:00</published><updated>2009-01-11T04:12:28.993-05:00</updated><title type='text'>Lucene: Multifield searches</title><content type='html'>&lt;p&gt;We can run multifield searches in Lucene using either the BooleanQuery API or using the MultiFieldQueryParser for parsing the query text. For e.g. If a index has 2 fields FirstName and LastName and if you need to search for "John" in the FirstName field and "Travis" in the LastName field one can use a Boolean Query as such: &lt;/p&gt;&lt;pre name="code" class="c-sharp"&gt;&lt;br /&gt;BooleanQuery bq = new BooleanQuery();&lt;br /&gt;Query qf = new TermQuery(new Lucene.Net.Index.Term("FirstName", "John"));&lt;br /&gt;Query ql = new TermQuery(new Lucene.Net.Index.Term("LastName", "Travis"));&lt;br /&gt;bq.Add(qf, BooleanClause.Occur.MUST);&lt;br /&gt;bq.Add(ql, BooleanClause.Occur.MUST);&lt;br /&gt;IndexSearcher srchr = new IndexSearcher(@"C:\indexDir");&lt;br /&gt;srchr.Search(bq);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt; Now if we need to search a single term across either of the FirstName and LastName fields then we can use the MultiFieldQueryParser as follows:&lt;br /&gt;&lt;pre name="code" class="c-sharp"&gt;&lt;br /&gt;Query query = MultiFieldQueryParser.parse("commonName",&lt;br /&gt;new String[] { "FirstName", "LastName" },&lt;br /&gt;new SimpleAnalyzer());&lt;br /&gt;srchr.Search(query);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt; Now if you need to search the term that must exist in both the fields then we use the following:&lt;br /&gt;&lt;pre name="code" class="c-sharp"&gt;&lt;br /&gt; Query query = MultiFieldQueryParser.Parse("commonName",&lt;br /&gt;new String[] { "FirstName", "LastName" },&lt;br /&gt;new BooleanClause.Occur[] { BooleanClause.Occur.MUST,BooleanClause.Occur.MUST}&lt;br /&gt;, new SimpleAnalyzer());&lt;br /&gt;srchr.Search(query);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt; Finally if you don’t want a term to occur in one of the Fields (say FirstName) then use:&lt;br /&gt;&lt;pre name="code" class="c-sharp"&gt;&lt;br /&gt; Query query = MultiFieldQueryParser.Parse("commonName",&lt;br /&gt;new String[] { "FirstName", "LastName" },&lt;br /&gt;new BooleanClause.Occur[] { BooleanClause.Occur.MUST_NOT,BooleanClause.Occur.MUST},&lt;br /&gt;new SimpleAnalyzer());&lt;br /&gt;srchr.Search(query);  &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt; &lt;div&gt;so if you need to search a single term across multiple fields then use MultiFieldQueryParser, if you need to search different terms in different fields then use the BooleanQuery as shown first&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-4350966255596572413?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/4350966255596572413/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=4350966255596572413' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/4350966255596572413'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/4350966255596572413'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2009/01/lucene-multifield-searches.html' title='Lucene: Multifield searches'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-5511951365340036793</id><published>2008-12-01T12:59:00.001-05:00</published><updated>2008-12-01T13:04:50.963-05:00</updated><title type='text'>Dynamically creating types using reflection and setting properties using Reflection.Emit.</title><content type='html'>I came across a requirement where we needed to create types dynamically based on XML Configuration files, so that in the furture new types are required we dont need to update the application again by creating a new class.  &lt;br/&gt; The additional requirement was to populate the property names of the class based on the Cml configuration and its values using the Querystring values from the HttpWebRequest. &lt;br/&gt; I earlier thought about using &lt;a target="_blank" href="http://msdn.microsoft.com/en-us/library/exczf7b9.aspx"&gt;Dynamic methods&lt;/a&gt; from .NET Framework 2.0, but that did not fit my purpose since I didn't need to execute methods from the dynamic type that was created. &lt;br/&gt;&lt;br/&gt; So here is the code: &lt;br/&gt; I created three helper methods &lt;br/&gt; 1. Generates the AssemblyBuilder and Module Builder objects  &lt;br/&gt; 2. Generates the TypeBuilder object.. which will be used for generating an instance of the dynamic type using Activator.CreateInstance  &lt;br/&gt;3. Create properties using Relection.Emit &lt;br/&gt; &lt;div&gt;&lt;div style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%;"&gt; &lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;class&lt;/span&gt; DynamicType&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;   3:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;   4:&lt;/span&gt;     &lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;static&lt;/span&gt; AssemblyBuilder asmBuilder = &lt;span style="color: #0000ff;"&gt;null&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;   5:&lt;/span&gt;     &lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;static&lt;/span&gt; ModuleBuilder modBuilder = &lt;span style="color: #0000ff;"&gt;null&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;   6:&lt;/span&gt;     &lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; GenerateAssemblyAndModule()&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;   7:&lt;/span&gt;     {&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;   8:&lt;/span&gt;         &lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (asmBuilder == &lt;span style="color: #0000ff;"&gt;null&lt;/span&gt;)&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;   9:&lt;/span&gt;         {&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  10:&lt;/span&gt;             AssemblyName assemblyName = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; AssemblyName();&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  11:&lt;/span&gt;             assemblyName.Name = &lt;span style="color: #006080;"&gt;"DWBeacons"&lt;/span&gt;;&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  12:&lt;/span&gt;             AppDomain thisDomain = Thread.GetDomain();&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  13:&lt;/span&gt;             asmBuilder = thisDomain.DefineDynamicAssembly(&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  14:&lt;/span&gt;                          assemblyName, AssemblyBuilderAccess.Run);&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  15:&lt;/span&gt;             modBuilder = asmBuilder.DefineDynamicModule(&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  16:&lt;/span&gt;                          asmBuilder.GetName().Name, &lt;span style="color: #0000ff;"&gt;false&lt;/span&gt;);&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  17:&lt;/span&gt;         }&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  18:&lt;/span&gt;     }&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  19:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  20:&lt;/span&gt;     &lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;static&lt;/span&gt; TypeBuilder CreateType(ModuleBuilder modBuilder, &lt;span style="color: #0000ff;"&gt;string&lt;/span&gt; typeName)&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  21:&lt;/span&gt;     {&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  22:&lt;/span&gt;         TypeBuilder typeBuilder = modBuilder.DefineType(typeName,&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  23:&lt;/span&gt;                     TypeAttributes.Public |&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  24:&lt;/span&gt;                     TypeAttributes.Class |&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  25:&lt;/span&gt;                     TypeAttributes.AutoClass |&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  26:&lt;/span&gt;                     TypeAttributes.AnsiClass |&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  27:&lt;/span&gt;                     TypeAttributes.BeforeFieldInit |&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  28:&lt;/span&gt;                     TypeAttributes.AutoLayout,&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  29:&lt;/span&gt;                     &lt;span style="color: #0000ff;"&gt;typeof&lt;/span&gt;(&lt;span style="color: #0000ff;"&gt;object&lt;/span&gt;));&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  30:&lt;/span&gt;         &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; typeBuilder;&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  31:&lt;/span&gt;     }&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  32:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  33:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  34:&lt;/span&gt;     &lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; CreateProperty(TypeBuilder t, &lt;span style="color: #0000ff;"&gt;string&lt;/span&gt; name, Type typ)&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  35:&lt;/span&gt;     {&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  36:&lt;/span&gt;         &lt;span style="color: #0000ff;"&gt;string&lt;/span&gt; field = &lt;span style="color: #006080;"&gt;"_"&lt;/span&gt; + name.ToLower();&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  37:&lt;/span&gt;         FieldBuilder fieldBldr = t.DefineField(field, typ, FieldAttributes.Private);&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  38:&lt;/span&gt;         PropertyBuilder propBldr = t.DefineProperty(name, PropertyAttributes.HasDefault, typ, &lt;span style="color: #0000ff;"&gt;null&lt;/span&gt;);&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  39:&lt;/span&gt;         MethodAttributes getSetAttr = MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig;&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  40:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  41:&lt;/span&gt;         MethodBuilder getPropBldr = t.DefineMethod(&lt;span style="color: #006080;"&gt;"get_"&lt;/span&gt; + name, getSetAttr, typ, Type.EmptyTypes);&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  42:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  43:&lt;/span&gt;         ILGenerator getIL = getPropBldr.GetILGenerator();&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  44:&lt;/span&gt;         getIL.Emit(OpCodes.Ldarg_0);&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  45:&lt;/span&gt;         getIL.Emit(OpCodes.Ldfld, fieldBldr);&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  46:&lt;/span&gt;         getIL.Emit(OpCodes.Ret);&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  47:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  48:&lt;/span&gt;         MethodBuilder setPropBldr = t.DefineMethod(&lt;span style="color: #006080;"&gt;"set_"&lt;/span&gt; + name, getSetAttr, &lt;span style="color: #0000ff;"&gt;null&lt;/span&gt;, &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; Type[] { typ });&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  49:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  50:&lt;/span&gt;         ILGenerator setIL = setPropBldr.GetILGenerator();&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  51:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  52:&lt;/span&gt;         setIL.Emit(OpCodes.Ldarg_0);&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  53:&lt;/span&gt;         setIL.Emit(OpCodes.Ldarg_1);&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  54:&lt;/span&gt;         setIL.Emit(OpCodes.Stfld, fieldBldr);&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  55:&lt;/span&gt;         setIL.Emit(OpCodes.Ret);&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  56:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  57:&lt;/span&gt;         propBldr.SetGetMethod(getPropBldr);&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  58:&lt;/span&gt;         propBldr.SetSetMethod(setPropBldr);&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  59:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  60:&lt;/span&gt;     }&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  61:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  62:&lt;/span&gt; }&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Then to use these helper methods from the Main program I used the following:&lt;br /&gt;&lt;div&gt;&lt;div style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%;"&gt;&lt;br /&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (DynamicType.asmBuilder == &lt;span style="color: #0000ff;"&gt;null&lt;/span&gt;)&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;   2:&lt;/span&gt;     DynamicType.GenerateAssemblyAndModule();&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;   3:&lt;/span&gt; finalType = DynamicType.modBuilder.GetType(&lt;span style="color: #006080;"&gt;"Beacon11"&lt;/span&gt;);&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;   4:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;   5:&lt;/span&gt; TypeBuilder tb = DynamicType.CreateType(DynamicType.modBuilder, typeName);&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;   6:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;   7:&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;foreach&lt;/span&gt; (XElement e &lt;span style="color: #0000ff;"&gt;in&lt;/span&gt; beaconNode.Descendants())&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;   8:&lt;/span&gt; {&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;   9:&lt;/span&gt;     &lt;span style="color: #0000ff;"&gt;string&lt;/span&gt; pname = e.Attribute(&lt;span style="color: #006080;"&gt;"qs"&lt;/span&gt;).Value;&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  10:&lt;/span&gt;     &lt;span style="color: #0000ff;"&gt;string&lt;/span&gt; ptype = e.Attribute(&lt;span style="color: #006080;"&gt;"type"&lt;/span&gt;).Value;&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  11:&lt;/span&gt;     DynamicType.CreateProperty(tb, pname, Type.GetType(ptype));&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  12:&lt;/span&gt; }&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  13:&lt;/span&gt; finalType = tb.CreateType();&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  14:&lt;/span&gt; &amp;nbsp;&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  15:&lt;/span&gt; Object obj = Activator.CreateInstance(finalType);&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  16:&lt;/span&gt; &lt;span style="color: #008000;"&gt;// this sets the properties of the just instantiated class&lt;/span&gt;&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  17:&lt;/span&gt; finalType.InvokeMember(&lt;span style="color: #006080;"&gt;"bv"&lt;/span&gt;, BindingFlags.SetProperty, &lt;span style="color: #0000ff;"&gt;null&lt;/span&gt;, data, &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;object&lt;/span&gt;[] { 1.0 });&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  18:&lt;/span&gt; finalType.InvokeMember(&lt;span style="color: #006080;"&gt;"tp"&lt;/span&gt;, BindingFlags.SetProperty, &lt;span style="color: #0000ff;"&gt;null&lt;/span&gt;, data, &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;object&lt;/span&gt;[] { 2.0 });&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  19:&lt;/span&gt; &lt;span style="color: #008000;"&gt;//this sets the properties of the type by using values from the querystring&lt;/span&gt;&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  20:&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;foreach&lt;/span&gt; (XElement e &lt;span style="color: #0000ff;"&gt;in&lt;/span&gt; beaconNode.Descendants())&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  21:&lt;/span&gt; {&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  22:&lt;/span&gt;     &lt;span style="color: #0000ff;"&gt;string&lt;/span&gt; pname = e.Attribute(&lt;span style="color: #006080;"&gt;"qs"&lt;/span&gt;).Value;&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  23:&lt;/span&gt;     &lt;span style="color: #0000ff;"&gt;object&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;value&lt;/span&gt; = context.Request.QueryString[pname];&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  24:&lt;/span&gt;     finalType.InvokeMember(pname, BindingFlags.SetProperty, &lt;span style="color: #0000ff;"&gt;null&lt;/span&gt;, data, &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;object&lt;/span&gt;[] { &lt;span style="color: #0000ff;"&gt;value&lt;/span&gt; });&lt;/pre&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;&lt;span style="color: #606060;"&gt;  25:&lt;/span&gt; }&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;For more information visit : &lt;a href="http://msdn.microsoft.com/en-us/library/system.reflection.emit.propertybuilder.aspx" target="_blank"&gt;msdn - PropertyBuilder&lt;/a&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-5511951365340036793?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/5511951365340036793/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=5511951365340036793' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/5511951365340036793'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/5511951365340036793'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2008/12/dynamically-creating-types-using.html' title='Dynamically creating types using reflection and setting properties using Reflection.Emit.'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-3924405795540805746</id><published>2008-11-18T13:32:00.001-05:00</published><updated>2008-11-18T13:34:57.372-05:00</updated><title type='text'>Schedule a task using C# code</title><content type='html'>I needed to schedule a task to run every day at 9:00 p.m. in the night. I had an addition al requirement that the task be scheduled only if the FileSystemwatcher alerts us of new files being available for processing.&lt;br/&gt;&lt;br/&gt;  Thus the files could be recieved anytime during the day, but despite that the task should be schduled to run exactly at 9:00 p.m. in the night.&lt;br/&gt;&lt;br/&gt;  So I used the following code to schedule a task(using System.Threading.Timer and TimeSpan classes) &lt;br/&gt;&lt;br/&gt;  &lt;div&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;DateTime d = DateTime.Now;&lt;br/&gt;&lt;br /&gt;timer = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; Timer(&lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; TimerCallback(Update), &lt;span style="color: #0000ff;"&gt;null&lt;/span&gt;, &lt;br /&gt;TimeSpan.FromMinutes(21 * 60 - (d.Hour * 60 + d.Minute)), &lt;br /&gt;TimeSpan.FromMilliseconds(-1));&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Note I used TimeSpan.FromMillisecnods(-1) to disable periodic signalling  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-3924405795540805746?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/3924405795540805746/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=3924405795540805746' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/3924405795540805746'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/3924405795540805746'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2008/11/schedule-task-using-c-code.html' title='Schedule a task using C# code'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-8483877860625290346</id><published>2008-11-13T14:40:00.001-05:00</published><updated>2008-11-13T14:40:13.760-05:00</updated><title type='text'>Compare 2 SQL queries for equality</title><content type='html'>&lt;div&gt;&lt;pre style="background-color: #f4f4f4; font-family: Consolas, 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt;  border-style: none; color: black; overflow: visible; padding: 0px 0px 0px 0px; width: 100%; margin: 0em;"&gt;DECLARE @check1 bigint&lt;br /&gt;DECLARE @check2 bigint&lt;br /&gt;&lt;br /&gt;Select @check1 = CHECKSUM_AGG(CHECKSUM(*))&lt;br /&gt;FROM&lt;br /&gt;(&lt;br /&gt;    SELECT *&lt;br /&gt;    FROM dbo.Orders (nolock)&lt;br /&gt;)&lt;br /&gt;AS Source&lt;br /&gt;&lt;br /&gt;Select @check2 = CHECKSUM_AGG(CHECKSUM(*))&lt;br /&gt;FROM&lt;br /&gt;(&lt;br /&gt;    SELECT *&lt;br /&gt;    FROM dbo.Orders (nolock)&lt;br /&gt;    WHERE IsSuccessful = 1&lt;br /&gt;)&lt;br /&gt;As Comparison&lt;br /&gt;&lt;br /&gt;IF @check1 = @check2&lt;br /&gt;    PRINT &lt;span style="color: #006080;"&gt;'Queries are Equal'&lt;/span&gt;&lt;br /&gt;ELSE&lt;br /&gt;    PRINT &lt;span style="color: #006080;"&gt;'Queries are NOT Equal'&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Note:&lt;br /&gt;If order of rows is different it will not effect the result &lt;br /&gt;It does not do execution plan comparisons, simply checks if the rows returned by the two queries are the same or not&lt;br /&gt;&lt;br /&gt;&lt;a href="http://blog.troyd.net/How+To+Compare++Test+The+Equality+Of+Two+Queries+In+SQL+Server+With+SQL.aspx" target="_blank"&gt;More info&lt;/a&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-8483877860625290346?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/8483877860625290346/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=8483877860625290346' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/8483877860625290346'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/8483877860625290346'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2008/11/compare-2-sql-queries-for-equality.html' title='Compare 2 SQL queries for equality'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-677665481818187195</id><published>2008-11-12T16:56:00.001-05:00</published><updated>2008-11-12T16:58:45.589-05:00</updated><title type='text'>Converting SQL2005 DBTimeStamp to Long for Comparison (Convert from Hex to long and decimal to Hex)</title><content type='html'>If you need to Convert SQL 2005 DB TimeStamp values to Long then follow these steps: &lt;br/&gt; 1. Retrieve the DB TimeStamp value in a Byte Array (8 bytes long). &lt;br/&gt; 2. Convert the byte array into a Hexadecimal string &lt;br/&gt; 3. Convert the hexadecimal string to a long &lt;br/&gt;  &lt;div&gt;   &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;long&lt;/span&gt; BytesToLong(&lt;span style="color: #0000ff"&gt;byte&lt;/span&gt;[] bytes)&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; ts = &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;byte&lt;/span&gt; b &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; bytes)&lt;br /&gt;        ts += b.ToString(&lt;span style="color: #006080"&gt;&amp;quot;X&amp;quot;&lt;/span&gt;).PadLeft(2,Convert.ToChar(&lt;span style="color: #006080"&gt;&amp;quot;0&amp;quot;&lt;/span&gt;));&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; Convert.ToInt64(ts, 16);&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;There is another method to convert the DBTimeStamp to Long, but I dont prefer this method since it can return negative values. The method is:&lt;br/&gt;&lt;br /&gt;1. Retrieve the DB TimeStamp value in a Byte Array (8 bytes long).&lt;br /&gt;2. Use BitConverter class to convert the byte array into long &lt;br /&gt;&lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;long result = BitConverter.ToInt64(dbTimestamp, 0); &lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;Inorder to remedy this use the following to generate the same long value as in step 1:&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;long&lt;/span&gt; FromDbTimestamp(&lt;span style="color: #0000ff"&gt;byte&lt;/span&gt;[] dbTimestamp)&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;long&lt;/span&gt; result = 0;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (dbTimestamp != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)&lt;br /&gt;    {&lt;br /&gt;        Array.Reverse(dbTimestamp);&lt;br /&gt;        result = BitConverter.ToInt64(dbTimestamp, 0);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; result;&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;Finally to convert a long into the correct DBTimeStamp use this: &lt;br /&gt;&lt;div&gt;&lt;br /&gt;  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;byte&lt;/span&gt;[] ToDbTimestamp(&lt;span style="color: #0000ff"&gt;long&lt;/span&gt; timestamp)&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;byte&lt;/span&gt;[] result = BitConverter.GetBytes(timestamp);&lt;br /&gt;    Array.Reverse(result);&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; result;&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-677665481818187195?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/677665481818187195/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=677665481818187195' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/677665481818187195'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/677665481818187195'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2008/11/converting-sql2005-dbtimestamp-to-long.html' title='Converting SQL2005 DBTimeStamp to Long for Comparison (Convert from Hex to long and decimal to Hex)'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-5250687481671371701</id><published>2008-10-13T13:23:00.001-04:00</published><updated>2008-10-13T18:12:08.292-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Passing state to threads via anonymous calls</title><content type='html'>&lt;p&gt;We already know that we can pass state into to Threads in 2 ways:&lt;/p&gt;  &lt;p&gt;1. using ParameterizedThreadStart delegate&lt;/p&gt; 2.using global variables(reference or value types) accessible to the main thread as well the instantiated thread. This is also the  way to share data amonst multiple threads. Infact the most common way to share data between threads is using static variables where application wide scope is desired. &lt;p&gt;3.using Thread.QueueUserWorkItem ... This differs from Parameterized ThreadStart delegate since it uses threads from a preconfigured ThreadPool instead of manually creating threads &lt;/p&gt;  There is another cool method to pass information to threads is via anonymous methods. For e.g.   &lt;div&gt;   &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Main&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; mainMessage = &lt;span style="color: #006080"&gt;&amp;quot;Hello from Main !!!&amp;quot;&lt;/span&gt;;&lt;br /&gt;    Thread t = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Thread(&lt;span style="color: #0000ff"&gt;delegate&lt;/span&gt;() { Print(mainMessage);});&lt;br /&gt;    t.Start();&lt;br /&gt;}&lt;br /&gt;&lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Print(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; message)&lt;br /&gt;{&lt;br /&gt;    Console.Writeline(message);&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;Advantage of using this technique is that, it provides strongly typed access to the parameters passed to the thread. The Target Method can accept &lt;strong&gt;&lt;u&gt;any&lt;/u&gt;&lt;/strong&gt; number of arguments, and no casting is required (unlike Parameterized Start where the passed state is an “object”) . The flip side, though, is that you must keep outer-variable semantics in mind &lt;br /&gt;&lt;br /&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-5250687481671371701?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/5250687481671371701/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=5250687481671371701' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/5250687481671371701'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/5250687481671371701'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2008/10/passing-state-to-threads-via-anonymous.html' title='Passing state to threads via anonymous calls'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-4916472706414653446</id><published>2008-09-26T20:57:00.004-04:00</published><updated>2008-10-13T18:12:08.292-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Method Hiding... Polymorphism in C#</title><content type='html'>&lt;h4&gt;In the following code:&lt;/h4&gt;  &lt;div&gt;   &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;interface&lt;/span&gt; IBand&lt;br /&gt; {&lt;br /&gt;     &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; ID {get;set;}&lt;br /&gt;     &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; Name {get;set;}&lt;br /&gt;     &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; GetStatus();&lt;br /&gt; }&lt;br /&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Band : IBand&lt;br /&gt; {&lt;br /&gt;     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; ID { get; set; }&lt;br /&gt;     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; Name { get; set; }&lt;br /&gt;&lt;br /&gt;     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; Band()&lt;br /&gt;     {&lt;br /&gt;         GetStatus();&lt;br /&gt;     }&lt;br /&gt;     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; GetStatus()&lt;br /&gt;     {&lt;br /&gt;         ID = 555;&lt;br /&gt;         Name = &lt;span style="color: #006080"&gt;&amp;quot;Ring&amp;quot;&lt;/span&gt;;&lt;br /&gt;         Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;Base Class Called&amp;quot;&lt;/span&gt;);&lt;br /&gt;     }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; ABand : Band, IBand&lt;br /&gt; {&lt;br /&gt;     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; Update { get; set; }&lt;br /&gt;&lt;br /&gt;     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ABand() : &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;() {}&lt;br /&gt;&lt;br /&gt;     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; GetStatus()&lt;br /&gt;     {&lt;br /&gt;         ID = 655;&lt;br /&gt;         Name = &lt;span style="color: #006080"&gt;&amp;quot;TEsst&amp;quot;&lt;/span&gt;;&lt;br /&gt;         Update = &lt;span style="color: #006080"&gt;&amp;quot;ddd&amp;quot;&lt;/span&gt;;&lt;br /&gt;         Console.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;Derived class Called&amp;quot;&lt;/span&gt;);&lt;br /&gt;     }&lt;br /&gt; }&lt;br /&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Program&lt;br /&gt; {&lt;br /&gt;     &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Main(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;[] args)&lt;br /&gt;     {&lt;br /&gt;         IBand band = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; ABand();&lt;br /&gt;         band.GetStatus();&lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt; }&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;p&gt;We have 2 classes, Band and ABand which implement the IBand interface explicitly.&lt;br /&gt;&lt;br /&gt;Now the call to band.GetStatus in Main will display &amp;quot;Derived class called&amp;quot;. This will only happen if the Derived class (ABand) also implements the interface IBand explicitly (not in the literal sense in that it does not implement the methods using the IBand.GetStatus syntax) &lt;br /&gt;&lt;br /&gt;If the ABand class does not implement the IBand interface explicitly (but implicitly since it inherits from Band which implements IBand) then the above code will output &amp;quot;Base class called&amp;quot; &lt;br /&gt;&lt;br /&gt;However note one thing, that when the CTor for ABand is invoked it will invoke the ctor Band class and which will call GetStatus() method from within Band class hence this will output &amp;quot;Base class called&amp;quot; even though the ABand class has implemented the IBand interface explicilty.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-4916472706414653446?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/4916472706414653446/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=4916472706414653446' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/4916472706414653446'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/4916472706414653446'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2008/09/method-hiding-polymorphism-in-c.html' title='Method Hiding... Polymorphism in C#'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-3109305841424623515</id><published>2008-09-09T20:23:00.002-04:00</published><updated>2008-09-09T20:42:32.169-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='LINQ'/><title type='text'>Linq To XML : Check for existence of an element</title><content type='html'>&lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;var bookQuery = &lt;br /&gt;from book &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; bookXml.Descendants(&lt;span style="color: #006080"&gt;&amp;quot;Item&amp;quot;&lt;/span&gt;)&lt;br /&gt;&lt;br /&gt;let attributes = book.Element(&lt;span style="color: #006080"&gt;&amp;quot;ItemAttributes&amp;quot;&lt;/span&gt;)&lt;br /&gt;&lt;br /&gt;let price = Decimal.Parse((&lt;br /&gt;  book.Elements(&lt;span style="color: #006080"&gt;&amp;quot;OfferSummary&amp;quot;&lt;/span&gt;).Any() &lt;br /&gt;  &amp;amp;&amp;amp; book.Element(&lt;span style="color: #006080"&gt;&amp;quot;OfferSummary&amp;quot;&lt;/span&gt;).Elements(&lt;span style="color: #006080"&gt;&amp;quot;LowestNewPrice&amp;quot;&lt;/span&gt;).Any()&lt;br /&gt;  ? book.Element(&lt;span style="color: #006080"&gt;&amp;quot;OfferSummary&amp;quot;&lt;/span&gt;).Element(&lt;span style="color: #006080"&gt;&amp;quot;LowestNewPrice&amp;quot;&lt;/span&gt;).Element(&lt;span style="color: #006080"&gt;&amp;quot;Amount&amp;quot;&lt;/span&gt;).Value&lt;br /&gt;  : (attributes.Elements(&lt;span style="color: #006080"&gt;&amp;quot;ListPrice&amp;quot;&lt;/span&gt;).Any()&lt;br /&gt;      ? attributes.Element(&lt;span style="color: #006080"&gt;&amp;quot;ListPrice&amp;quot;&lt;/span&gt;).Element(&lt;span style="color: #006080"&gt;&amp;quot;Amount&amp;quot;&lt;/span&gt;).Value &lt;br /&gt;      : &lt;span style="color: #006080"&gt;&amp;quot;0&amp;quot;&lt;/span&gt;))) / 100&lt;br /&gt;&lt;br /&gt;select &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; {Price = price};&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The trick is to use the Elements(“node”) instead of Element(“node”) and then use the Any() function which will return true if an element of that name exists.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;Some other LINQ tips:&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Some of the extensions that one can use are Intersect,Union &amp;amp;&amp;amp; Except &lt;br /&gt;  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;var list1 = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; List&amp;lt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;&amp;gt; { 2, 4, 9, 11, 3, 6 };&lt;br /&gt;var list2 = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; List&amp;lt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;&amp;gt; { 3, 8, 4, 30, 9, 16 };&lt;br /&gt;var newlist = list1.Intersect(list2);&lt;/pre&gt;&lt;br /&gt;This returns : 3,4,9&lt;br /&gt;newlist = list1.Union(list2);&lt;br /&gt;this returns : 2,3,4,6,8,9,11,16,30. finally &lt;br /&gt;newlist = list1.Except(list2);&lt;br /&gt;returns : 2,11,6&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-3109305841424623515?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/3109305841424623515/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=3109305841424623515' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/3109305841424623515'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/3109305841424623515'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2008/09/linq-to-xml-check-for-existence-of.html' title='Linq To XML : Check for existence of an element'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-8054519056156161156</id><published>2008-08-26T14:57:00.001-04:00</published><updated>2008-10-13T18:12:17.077-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Convert Array of Ints into bytes</title><content type='html'>&lt;p&gt;Here is the code to convert array of Ints to bytes:&lt;/p&gt;  &lt;div&gt;   &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[] source = ids.ToArray();&lt;br /&gt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; length = source.Length * 4;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;byte&lt;/span&gt;[] dest = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #0000ff"&gt;byte&lt;/span&gt;[length];&lt;br /&gt;System.Buffer.BlockCopy(source, 0, dest, 0, dest.Length);&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-8054519056156161156?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/8054519056156161156/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=8054519056156161156' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/8054519056156161156'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/8054519056156161156'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2008/08/convert-array-of-ints-into-bytes.html' title='Convert Array of Ints into bytes'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-3555409414658348433</id><published>2008-07-25T12:44:00.001-04:00</published><updated>2008-10-13T18:12:25.244-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='aspnet20'/><title type='text'>Alternating styles in ListView- without AlternatingItemTemplate</title><content type='html'>&lt;p&gt;From within any template, you have access to the current index of the row within the whole data set, using &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listviewdataitem.dataitemindex.aspx"&gt;Container.DataItemIndex&lt;/a&gt;, and within the currently displayed items, using &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listviewdataitem.displayindex.aspx"&gt;Container.DisplayIndex&lt;/a&gt;. This gives us an easy way to alternate styles:&lt;/p&gt;  &lt;pre&gt;&amp;lt;ItemTemplate&amp;gt;&lt;br /&gt;  &amp;lt;li class=&amp;quot;&amp;lt;%# Container.DisplayIndex % 2 == 0 ? &amp;quot;even&amp;quot; : &amp;quot;odd&amp;quot; %&amp;gt;&amp;quot;&amp;gt;&lt;br /&gt;    &amp;lt;%# Eval(&amp;quot;Name&amp;quot;) %&amp;gt;&lt;br /&gt;  &amp;lt;/li&amp;gt;&lt;br /&gt;&amp;lt;/ItemTemplate&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Just define the even and odd classes in your stylesheet and you're pretty much done.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-3555409414658348433?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/3555409414658348433/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=3555409414658348433' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/3555409414658348433'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/3555409414658348433'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2008/07/alternating-styles-in-listview-without.html' title='Alternating styles in ListView- without AlternatingItemTemplate'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-6547370845336329128</id><published>2008-07-24T22:53:00.001-04:00</published><updated>2008-07-24T23:01:00.687-04:00</updated><title type='text'>Batch Inserts to SQL Server- Stored procedure method</title><content type='html'>&lt;p&gt;To do batch Updates to SQL server &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Create DataTable or DataSet and populate it with required rows &lt;/li&gt;    &lt;li&gt;Next Create a SqlCommand and SqlDataAdapter using that SqlCommand &lt;/li&gt;    &lt;li&gt;Remember to set the UpdateRowSource property on the Command the the appropriate value&lt;/li&gt;    &lt;li&gt;Set the UpdateBatchSize Property on the SqlDataAdapter &lt;/li&gt;    &lt;li&gt;then call SqlDataAdapter.Update(dt) to push the updates to SQL server &lt;/li&gt; &lt;/ul&gt;  &lt;div&gt;   &lt;div&gt;     &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;DataTable dt = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DataTable();&lt;br /&gt;dt.Columns.Add(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DataColumn(&lt;span style="color: #006080"&gt;&amp;quot;asin&amp;quot;&lt;/span&gt;));&lt;br /&gt;dt.Columns.Add(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DataColumn(&lt;span style="color: #006080"&gt;&amp;quot;trackasin&amp;quot;&lt;/span&gt;));&lt;br /&gt;dt.Columns.Add(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DataColumn(&lt;span style="color: #006080"&gt;&amp;quot;isrc&amp;quot;&lt;/span&gt;));&lt;br /&gt;&lt;span style="color: #0000ff"&gt;for&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; i =0; i &amp;lt; 2000;i++)&lt;br /&gt;{&lt;br /&gt;    DataRow dr = dt.NewRow();&lt;br /&gt;    dr[&lt;span style="color: #006080"&gt;&amp;quot;asin&amp;quot;&lt;/span&gt;] = asin;&lt;br /&gt;    dr[&lt;span style="color: #006080"&gt;&amp;quot;trackasin&amp;quot;&lt;/span&gt;] = trackasin;&lt;br /&gt;    dr[&lt;span style="color: #006080"&gt;&amp;quot;isrc&amp;quot;&lt;/span&gt;] = isrc;&lt;br /&gt;    &lt;span style="color: #008000"&gt;//dr.RowState = DataRowState.Added;&lt;/span&gt;&lt;br /&gt;    dt.Rows.Add(dr);&lt;br /&gt;}&lt;br /&gt;------------------------------------------------&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; (SqlConnection connection = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; SqlConnection(ConfigurationManager.ConnectionStrings[&lt;span style="color: #006080"&gt;&amp;quot;MySpaceMusic&amp;quot;&lt;/span&gt;].ConnectionString))&lt;br /&gt;{&lt;br /&gt;    SqlCommand command = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; SqlCommand(INSERT_TRACK, connection);&lt;br /&gt;    command.CommandType = CommandType.StoredProcedure;&lt;br /&gt;    command.UpdatedRowSource = UpdateRowSource.None;&lt;br /&gt;    command.CommandTimeout = commandTimeout;&lt;br /&gt;&lt;br /&gt;    command.Parameters.Add(&lt;span style="color: #006080"&gt;&amp;quot;@asin&amp;quot;&lt;/span&gt;, SqlDbType.VarChar, 255, dt.Columns[0].ColumnName);&lt;br /&gt;    command.Parameters.Add(&lt;span style="color: #006080"&gt;&amp;quot;@trackAsin&amp;quot;&lt;/span&gt;, SqlDbType.VarChar, 255, dt.Columns[1].ColumnName);&lt;br /&gt;    command.Parameters.Add(&lt;span style="color: #006080"&gt;&amp;quot;@isrc&amp;quot;&lt;/span&gt;, SqlDbType.VarChar, 600, dt.Columns[2].ColumnName);&lt;br /&gt;&lt;br /&gt;    SqlDataAdapter adpt = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; SqlDataAdapter();&lt;br /&gt;&lt;br /&gt;    adpt.InsertCommand = command;&lt;br /&gt;    adpt.UpdateBatchSize = batchSize;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;try&lt;/span&gt;&lt;br /&gt;    {&lt;br /&gt;        connection.Open();&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; recordsInserted = adpt.Update(dt);&lt;br /&gt;    }&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;finally&lt;/span&gt;&lt;br /&gt;    {&lt;br /&gt;        adpt.Dispose();&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;  &lt;/div&gt;&lt;br /&gt;&lt;/div&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-6547370845336329128?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/6547370845336329128/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=6547370845336329128' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/6547370845336329128'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/6547370845336329128'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2008/07/batch-inserts-to-sql-server-stored.html' title='Batch Inserts to SQL Server- Stored procedure method'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-1798885924883133403</id><published>2008-07-03T01:42:00.002-04:00</published><updated>2008-07-03T01:44:53.424-04:00</updated><title type='text'>क्यूट सोंग .. नानी तेरी मोरनी को मोर ले गए</title><content type='html'>Naani Teri Morni Ko Mor Le Gaye &lt;br /&gt;Baaki Jo Bacha Tha Kaale Chor Le Gaye&lt;br /&gt;&lt;br /&gt; Khaake Peeke Mote Hoke, &lt;br /&gt;Chor Baithe Rail Mein &lt;br /&gt;Choron Vaala Dibba Kat Ke, Pahuncha Seedhe Jail Mein &lt;br /&gt;&lt;br /&gt;Naani Teri Morni Ko... &lt;br /&gt;&lt;br /&gt;Un Choron Ki Khoob Khabar Li, &lt;br /&gt;Mote Thaanedaar Ne &lt;br /&gt;Moron Ko Bhi Khoob Nachaaya, &lt;br /&gt;Jungal Ki Sarkaar Ne &lt;br /&gt;&lt;br /&gt;Naani Teri Morni Ko... &lt;br /&gt;Achhi Naani Pyaari Naani, &lt;br /&gt;Roosa-Roosi Chhod De Jaldi Se Ek Paisa De De, &lt;br /&gt;Tu Kanjoosi chod de...&lt;br /&gt;&lt;br /&gt;Nani teri morni ko chor le gaye&lt;br /&gt;baaki jo bacha tha kaale chor le gaye&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-1798885924883133403?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/1798885924883133403/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=1798885924883133403' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/1798885924883133403'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/1798885924883133403'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2008/07/blog-post.html' title='क्यूट सोंग .. नानी तेरी मोरनी को मोर ले गए'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-4999513503733434952</id><published>2008-05-06T01:56:00.001-04:00</published><updated>2008-05-06T01:56:54.211-04:00</updated><title type='text'>Unity Application block and Generic Singleton</title><content type='html'>&lt;p&gt;Here are some features of the Unity Application block. (Note there is overhead in using this block&amp;#8230; i.e. overhead while creating instances of objects that have dependent objects)&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/cc440954.aspx"&gt;http://msdn.microsoft.com/en-us/library/cc440954.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160; Highlights of the Unity Application Block &lt;/p&gt;  &lt;p&gt;&lt;a name="sectionToggle2"&gt;&lt;/a&gt;&lt;a name="intro_highlights"&gt;&lt;/a&gt;The Unity Application Block includes the following features:&lt;/p&gt;  &lt;p&gt;&amp;#183; It provides a mechanism for building (or assembling) instances of objects, which may contain other dependent object instances. &lt;/p&gt;  &lt;p&gt;&amp;#183; It exposes &lt;b&gt;RegisterType&lt;/b&gt; methods that support configuring the container with type mappings and objects (&lt;b&gt;including singleton instances&lt;/b&gt;) and &lt;b&gt;Resolve&lt;/b&gt; methods that return instances of built objects that can contain any dependent objects. &lt;/p&gt;  &lt;p&gt;&amp;#183; It provides inversion of control (IoC) functionality by allowing injection of preconfigured objects into classes built by the application block. Developers can specify an interface or class type in the constructor (constructor injection) or apply to properties and methods attributes to initiate property injection and method call injection. &lt;/p&gt;  &lt;p&gt;&amp;#183; It supports a hierarchy for containers. A container may have child container(s), allowing object location queries to pass from the child out through the parent container(s). &lt;/p&gt;  &lt;p&gt;&amp;#183; &lt;b&gt;It can read configuration information from standard configuration systems, such as XML files, and use it to configure the containe&lt;/b&gt;r( The Unity Container which hold references to the objects built using Resolve method). &lt;/p&gt;  &lt;p&gt;&amp;#183; It makes no demands on the object class definition. There is no requirement to apply attributes to classes (except when using property or method call injection), and there are no limitations on the class declaration. &lt;/p&gt;  &lt;p&gt;&amp;#183; It supports custom container extensions that developers can implement; for example, methods to allow additional object construction and container features such as caching. &lt;/p&gt;  &lt;p&gt;And here is the code for the Generic Singleton:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;/// Provides a Singleton implementation using Generics.&lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;/// &amp;lt;typeparam name=&amp;quot;T&amp;quot;&amp;gt;Type of singleton instance&amp;lt;/typeparam&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;sealed&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Singleton&amp;lt;T&amp;gt; &lt;span class="kwrd"&gt;where&lt;/span&gt; T : &lt;span class="kwrd"&gt;new&lt;/span&gt;()&lt;br /&gt;        {&lt;br /&gt;            Singleton() { }&lt;br /&gt;            &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; T Instance&lt;br /&gt;            {&lt;br /&gt;                get&lt;br /&gt;                { &lt;span class="kwrd"&gt;return&lt;/span&gt; Nested.instance; }&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;             &lt;span class="kwrd"&gt;class&lt;/span&gt; Nested&lt;br /&gt;            {&lt;br /&gt;                &lt;span class="rem"&gt;// Explicit static constructor to tell C# compiler&lt;/span&gt;&lt;br /&gt;                &lt;span class="rem"&gt;// not to mark type as beforefieldinit&lt;/span&gt;&lt;br /&gt;                &lt;span class="kwrd"&gt;static&lt;/span&gt; Nested() { }&lt;br /&gt;                &lt;span class="kwrd"&gt;internal&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; T instance = &lt;span class="kwrd"&gt;new&lt;/span&gt; T();&lt;br /&gt;            }&lt;br /&gt;        }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The code for returning the instance then becomes:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; BlogSettings Instance&lt;br /&gt;        {&lt;br /&gt;            get&lt;br /&gt;            {&lt;br /&gt;                &lt;span class="kwrd"&gt;return&lt;/span&gt; Utils.Singleton&amp;lt;BlogSettings&amp;gt;.Instance;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;You have to also change the constructor for BlogSettings to public to allow this this to work&lt;/pre&gt;&lt;br /&gt;&lt;style type="text/css"&gt;&lt;br /&gt;.csharpcode, .csharpcode pre&lt;br /&gt;{&lt;br /&gt;	font-size: small;&lt;br /&gt;	color: black;&lt;br /&gt;	font-family: consolas, "Courier New", courier, monospace;&lt;br /&gt;	background-color: #ffffff;&lt;br /&gt;	/*white-space: pre;*/&lt;br /&gt;}&lt;br /&gt;.csharpcode pre { margin: 0em; }&lt;br /&gt;.csharpcode .rem { color: #008000; }&lt;br /&gt;.csharpcode .kwrd { color: #0000ff; }&lt;br /&gt;.csharpcode .str { color: #006080; }&lt;br /&gt;.csharpcode .op { color: #0000c0; }&lt;br /&gt;.csharpcode .preproc { color: #cc6633; }&lt;br /&gt;.csharpcode .asp { background-color: #ffff00; }&lt;br /&gt;.csharpcode .html { color: #800000; }&lt;br /&gt;.csharpcode .attr { color: #ff0000; }&lt;br /&gt;.csharpcode .alt &lt;br /&gt;{&lt;br /&gt;	background-color: #f4f4f4;&lt;br /&gt;	width: 100%;&lt;br /&gt;	margin: 0em;&lt;br /&gt;}&lt;br /&gt;.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;style type="text/css"&gt;&lt;br /&gt;.csharpcode, .csharpcode pre&lt;br /&gt;{&lt;br /&gt;	font-size: small;&lt;br /&gt;	color: black;&lt;br /&gt;	font-family: consolas, "Courier New", courier, monospace;&lt;br /&gt;	background-color: #ffffff;&lt;br /&gt;	/*white-space: pre;*/&lt;br /&gt;}&lt;br /&gt;.csharpcode pre { margin: 0em; }&lt;br /&gt;.csharpcode .rem { color: #008000; }&lt;br /&gt;.csharpcode .kwrd { color: #0000ff; }&lt;br /&gt;.csharpcode .str { color: #006080; }&lt;br /&gt;.csharpcode .op { color: #0000c0; }&lt;br /&gt;.csharpcode .preproc { color: #cc6633; }&lt;br /&gt;.csharpcode .asp { background-color: #ffff00; }&lt;br /&gt;.csharpcode .html { color: #800000; }&lt;br /&gt;.csharpcode .attr { color: #ff0000; }&lt;br /&gt;.csharpcode .alt &lt;br /&gt;{&lt;br /&gt;	background-color: #f4f4f4;&lt;br /&gt;	width: 100%;&lt;br /&gt;	margin: 0em;&lt;br /&gt;}&lt;br /&gt;.csharpcode .lnum { color: #606060; }&lt;/style&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-4999513503733434952?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/4999513503733434952/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=4999513503733434952' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/4999513503733434952'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/4999513503733434952'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2008/05/unity-application-block-and-generic.html' title='Unity Application block and Generic Singleton'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-816999454005132499</id><published>2008-04-30T17:03:00.001-04:00</published><updated>2008-04-30T17:03:25.225-04:00</updated><title type='text'>Debugging Win Service</title><content type='html'>&lt;p&gt;For debugging a Startup of Windows Service add the call to the Method Debugger.Launch or Debugger.Break. This call can be placed in the Constructor of the Service.cs or in the first line of the OnStart() method.&lt;/p&gt;  &lt;p&gt;Calling &lt;a href="http://msdn2.microsoft.com/en-us/library/system.diagnostics.debugger.launch.aspx"&gt;Debugger.Launch()&lt;/a&gt; or &lt;a href="http://msdn2.microsoft.com/en-us/library/system.diagnostics.debugger.break.aspx"&gt;Debugger.Break()&lt;/a&gt; in your code allow you to debug such problems.&lt;/p&gt;  &lt;p&gt;For debugging an already running WindowService, simply attach the Debugger to to an existing process using &amp;quot;Debug\Attach to Process&amp;quot; menu item in VS 2005/VS 2008.&lt;/p&gt;  &lt;hr /&gt;  &lt;p&gt;&lt;b&gt;Visual Linq&lt;/b&gt; is a tool to visually create your Linq to SQL queries: &lt;a href="http://code.msdn.microsoft.com/vlinq"&gt;http://code.msdn.microsoft.com/vlinq&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;   &lt;hr /&gt;&lt;strong&gt;A Primer on WCF :&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;It is all about Service Contracts, Operation Contracts, Data Contracts and Fault Contracts and other type of Contracts&lt;/p&gt;  &lt;p&gt;Contracts usually enforced on Interfaces and the Classes then implement these interfaces.&lt;/p&gt;  &lt;p&gt;If Service Contract, Operation Contract attributes are applied to classes then we have an additional advantage that the methods can be marked private and can still be accessed by WCF clients.&lt;/p&gt;  &lt;p&gt;DataContracts are used to create .NET objects that can be sent to/fro between the client and the WCF Service. thus the DataMember attribute tells the runtime which properties need to be serialized/deserialized by the framework before being passed onto the network.&lt;/p&gt;  &lt;p&gt;We dont need DataContracts for Intrinsic objects like Int32, string etc since they are natively serializable&lt;/p&gt;  &lt;p&gt;FaultContracts can be applied to methods and can be used by the Client to determine what exceptions occurred at the server during processing of the request. Thus .NET exceptions are converted to FaultExceptions which are then sent over the wire as SOAP faults and then the client can reconstruct them to extract the Fault Detail from the FaultException&lt;/p&gt;  &lt;p&gt;A good introduction to WCF can be found here: &lt;a href="http://www.google.com/url?sa=t&amp;amp;ct=res&amp;amp;cd=1&amp;amp;url=http%3A%2F%2Fwww.davidchappell.com%2FIntroducingWCFv1.2.1.pdf&amp;amp;ei=VdoYSNOdC4eSpwTXsfn6CA&amp;amp;usg=AFQjCNEnWg_BM0dLR9CuADbAvauWCf8gRw&amp;amp;sig2=1_j4m4Z53P2ZviBr-MLTQQ" target="_blank"&gt;David Chappell's intro to WCF&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Bindings and endpoints form the heart of WCF, we can have different kinds of bindings, &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;BasicHTTPBinding which allows Http and HTTPS access.&lt;/li&gt;    &lt;li&gt;WSHttpBinding which adds the WS specifications to the binding to provide for reliability, transactions, security and other features.&lt;/li&gt;    &lt;li&gt;WSDualHttpBinding: use this for two-way communication between client and service, only HTTP is supported&lt;/li&gt;    &lt;li&gt;FederatedBinding: which means that if authenticated by one of the services, then the same ticket can be used to authenticate the client to other WCF/Java services&lt;/li&gt;    &lt;li&gt;NETTCPBinding : used when communicating using TCP protocol as the transport&lt;/li&gt;    &lt;li&gt;NamedPipeBinding: used within the local machine for inter process communication on the same machine.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Endpoints define how the service can be accessed by the client. Each WCF Service exposes endpoints to clients to publicize their services. Specify a different endpoint for each binding used by your service, thus the same machine can expose the service over HTTP and TCP using basicHttpBinding and NetTcpBinding respoectively and thus exposing endpoints for each of them. Endpoints consist of address, behavior etc&lt;/p&gt;  &lt;p&gt;John Sharp's &lt;a href="http://www.google.com/url?sa=t&amp;amp;ct=res&amp;amp;cd=1&amp;amp;url=http%3A%2F%2Fwww.microsoft.com%2FMSPress%2Fbooks%2F10022.aspx&amp;amp;ei=Ut4YSI-iDJaEpASp49mHCQ&amp;amp;usg=AFQjCNGU1QKlIIpmhqHFpMyzfbXMFn8_WA&amp;amp;sig2=Rv8g7Nv_ujiU_xkKA9HSPw" target="_blank"&gt;WCF Step by Step from Microsoft Press&lt;/a&gt; is an excellent book to get started.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-816999454005132499?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/816999454005132499/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=816999454005132499' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/816999454005132499'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/816999454005132499'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2008/04/debugging-win-service.html' title='Debugging Win Service'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-9010650091937342799</id><published>2008-04-06T19:31:00.001-04:00</published><updated>2008-04-06T19:31:22.811-04:00</updated><title type='text'>Get back almost 1GB of free disk space after Vista SP1 installation</title><content type='html'>&lt;p&gt;If you have installed SP1 of Vista you certainly recognized that your drive lost around 1Gb of free space. &lt;/p&gt;  &lt;p&gt;The solution is to use a tool that comes with the SP1 to recover your free space at the price of not being able to come back and uninstall the SP1. &lt;/p&gt;  &lt;p&gt;This tool is vsp1cln.exe that you can run like this:&lt;/p&gt; &lt;a href="http://lh3.google.com/rbg.net/R_ldSXrg4aI/AAAAAAAAAGU/EjeUGPgwBBg/vistasp1%5B5%5D.jpg"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="256" alt="vistasp1" src="http://lh4.google.com/rbg.net/R_ldSnrg4bI/AAAAAAAAAGc/XF_bxOtAGbs/vistasp1_thumb%5B3%5D.jpg" width="643" border="0" /&gt;&lt;/a&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-9010650091937342799?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/9010650091937342799/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=9010650091937342799' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/9010650091937342799'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/9010650091937342799'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2008/04/get-back-almost-1gb-of-free-disk-space_06.html' title='Get back almost 1GB of free disk space after Vista SP1 installation'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-2750246316829155239</id><published>2008-03-27T14:18:00.000-04:00</published><updated>2008-03-27T14:18:16.286-04:00</updated><title type='text'>Add Windows Explorer to your Visual Studio tools menu</title><content type='html'>&lt;a href="http://dotnettipoftheday.org/tips/explorer-in-tools-menu.aspx"&gt;.NET Tip of The Day: Add Windows Explorer to your Visual Studio tools menu&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-2750246316829155239?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://dotnettipoftheday.org/tips/explorer-in-tools-menu.aspx' title='Add Windows Explorer to your Visual Studio tools menu'/><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/2750246316829155239/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=2750246316829155239' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/2750246316829155239'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/2750246316829155239'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2008/03/add-windows-explorer-to-your-visual.html' title='Add Windows Explorer to your Visual Studio tools menu'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-958909116162644343</id><published>2008-03-03T20:41:00.001-05:00</published><updated>2008-10-13T18:33:32.405-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='PFX'/><title type='text'>Concurrency and Co-ordination Runtime - CCR</title><content type='html'>&lt;p&gt;Pretty cool Library from Microsoft for performing concurrent operations like multithreading operations and async tasks. Essenitally you get a guide to migrate all your APM ( Asynchronous Programming Model) tasks to the CCR tasks so that synchronization and co-ordination issues are automatically handled for you behind the scenes. &lt;/p&gt;  &lt;p&gt;Some of the good links on CCR are: &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=1424&amp;amp;SiteID=1"&gt;MSDN Forum&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&amp;#160;&lt;a href="http://iodyne.blogspot.com/"&gt;Nick Gunn's blog&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.google.com/url?sa=t&amp;amp;ct=res&amp;amp;cd=1&amp;amp;url=http%3A%2F%2Fmsdn.microsoft.com%2Fmsdnmag%2Fissues%2F06%2F09%2FConcurrentAffairs%2Fdefault.aspx&amp;amp;ei=M2TMR-eJMIvApgSJpbj0Dw&amp;amp;usg=AFQjCNE-2O20FgjyrAHfmu7SMvHP5ux8eg&amp;amp;sig2=uZMQhxusI2JZL9WwMtqlkA"&gt;Jeffrey Richters MSDN Magazine article&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://channel9.msdn.com/wiki/default.aspx/Channel9.ConcurrencyRuntime"&gt;Channel 9 link&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-958909116162644343?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/958909116162644343/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=958909116162644343' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/958909116162644343'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/958909116162644343'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2008/03/concurrency-and-co-ordination-runtime.html' title='Concurrency and Co-ordination Runtime - CCR'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-4791155007989662956</id><published>2008-02-08T11:29:00.000-05:00</published><updated>2008-10-13T18:33:39.184-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='aspnet20'/><title type='text'>ASP.NET State Server and Load Balancer</title><content type='html'>These are great links:&lt;br /&gt;&lt;a href="http://blog.maartenballiauw.be/post/2007/11/ASPNET-load-balancing-and-ASPNET-state-server-(aspnet_state).aspx"&gt;ASP.NET load balancing and ASP.NET state server (aspnet_state)&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://weblogs.asp.net/joestagner/archive/2008/01/31/maarten-balliauw-on-asp-net-load-balancing-and-the-asp-net-state-server.aspx"&gt;Session state ...State Server&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-4791155007989662956?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/4791155007989662956/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=4791155007989662956' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/4791155007989662956'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/4791155007989662956'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2008/02/aspnet-state-server-and-load-balancer.html' title='ASP.NET State Server and Load Balancer'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-9190680612667432911</id><published>2008-01-09T15:40:00.000-05:00</published><updated>2008-01-09T15:45:46.146-05:00</updated><title type='text'>How to check email works with no SMTP</title><content type='html'>There is a way to send e-mails with no SMTP server set up. Just configure your .NET application to drop e-mails into a specified folder instead of sending them via SMTP server&lt;br /&gt;&lt;!--&lt;br /&gt;{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red163\green21\blue21;\red255\green0\blue0;\red0\green0\blue0;}??\fs20 \cf1   &amp;lt;\cf3 system.net\cf1 &amp;gt;\par ??    &amp;lt;\cf3 mailSettings\cf1 &amp;gt;\par ??      &amp;lt;\cf3 smtp\cf1  \cf4 deliveryMethod\cf1 =\cf0 "\cf1 SpecifiedPickupDirectory\cf0 "\cf1 &amp;gt;\par ??        &amp;lt;\cf3 specifiedPickupDirectory\cf1  \cf4 pickupDirectoryLocation\cf1 =\cf0 "\cf1 c:\\Rohit\\\cf0 "\cf1  /&amp;gt;\par ??      &amp;lt;/\cf3 smtp\cf1 &amp;gt;\par ??    &amp;lt;/\cf3 mailSettings\cf1 &amp;gt;\par ??  &amp;lt;/\cf3 system.net\cf1 &amp;gt;}&lt;br /&gt;--&gt;&lt;br /&gt;&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515;"&gt;system.net&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515;"&gt;mailSettings&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515;"&gt;smtp&lt;/span&gt;&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;deliveryMethod&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;SpecifiedPickupDirectory&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515;"&gt;specifiedPickupDirectory&lt;/span&gt;&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;pickupDirectoryLocation&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;c:\Rohit\&lt;/span&gt;"&lt;span style="color: blue;"&gt; /&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515;"&gt;smtp&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp; &amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515;"&gt;mailSettings&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515;"&gt;system.net&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;This will instruct SmtpClient class to generate mail message, save it as .eml file and drop it into c:\Test\ folder&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-9190680612667432911?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/9190680612667432911/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=9190680612667432911' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/9190680612667432911'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/9190680612667432911'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2008/01/how-to-check-email-works-with-no-smtp.html' title='How to check email works with no SMTP'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-3305007966524727418</id><published>2008-01-08T10:20:00.000-05:00</published><updated>2008-01-08T10:22:12.316-05:00</updated><title type='text'>Using CompareValidator for just Data Validation</title><content type='html'>&lt;strong&gt;A simple method to validate an integer, double, date, or currency values entered into a textbox on ASP.NET page &lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;br /&gt;&lt;/strong&gt;Normally the CompareValidator is used to check one value against another on ASP.NET page. However it also can be used to ensure user has entered data in a correct format. (Data Validation)&lt;br /&gt;&lt;br /&gt;Here's how it works:&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Set the ControlToValidate property to the ID of the TextBox. &lt;/li&gt;&lt;li&gt;Set the Operator property to DataTypeCheck. &lt;/li&gt;&lt;li&gt;Assign a ValidationDataType enumeration member to the Type property, which includes either one of the following : String, Integer, Double, Date, and Currency. &lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-3305007966524727418?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/3305007966524727418/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=3305007966524727418' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/3305007966524727418'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/3305007966524727418'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2008/01/using-comparevalidator-for-just-data.html' title='Using CompareValidator for just Data Validation'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-5630965137964590035</id><published>2008-01-03T09:36:00.000-05:00</published><updated>2008-10-13T18:33:59.479-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='XML'/><title type='text'>using FOR XMLPATH to concat multiple row values</title><content type='html'>The need is to concatenate multiple row values from a table&lt;br /&gt;The following TSQL in SQL 2005 can assist in returning values&lt;br /&gt;&lt;br /&gt;Following is the input table&lt;br /&gt;ID Value&lt;br /&gt;---------&lt;br /&gt;1 '-'&lt;br /&gt;1 'C'&lt;br /&gt;1 'B'&lt;br /&gt;1 'A'&lt;br /&gt;2 '='&lt;br /&gt;2 'G'&lt;br /&gt;2 'D'&lt;br /&gt;=======&lt;br /&gt;Expected output :&lt;br /&gt;ID Concat&lt;br /&gt;1 '-CBA'&lt;br /&gt;2 '=GD'&lt;br /&gt;=================&lt;br /&gt;&lt;br /&gt;TSQL for this :&lt;br /&gt;select Distinct ID, o.List&lt;br /&gt;from &lt;br /&gt;#t1 A&lt;br /&gt;CROSS APPLY&lt;br /&gt;(&lt;br /&gt; select Val as [text()] from #t1 B&lt;br /&gt; where B.ID = A.ID&lt;br /&gt; FOR XML PATH('')&lt;br /&gt;) o (List)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-5630965137964590035?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/5630965137964590035/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=5630965137964590035' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/5630965137964590035'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/5630965137964590035'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2008/01/using-for-xmlpath-to-concat-multiple.html' title='using FOR XMLPATH to concat multiple row values'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-7279401154109620077</id><published>2007-12-25T17:39:00.000-05:00</published><updated>2008-10-13T18:34:07.633-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sql2005'/><title type='text'>SQL Server (user) instances and AutoAttach DB</title><content type='html'>&lt;span style="font-family:times new roman;font-size:105%;"&gt;Developers often need to attach databases on demand and then start using them immediately. However before developers can start working with DB's they need to first attach the DB, then create a SQL login and then add that login to the DB users list. with SQL Express this is no longer a requirement.&lt;br /&gt;&lt;br /&gt;With SQL Express we can use Auto Attach DB's and User instances.&lt;br /&gt;SQL 2005 Express and Full editions both support autoAttachment of DB's, however User instancing is only supported with SQL Express.&lt;br /&gt;&lt;br /&gt;To enable AutoAttachment of DB's use : AttachDbFilename=db.mdf in connection string.&lt;br /&gt;When you use "AttachDbFilename=|DataDirectory|db.mdf" the connection string automatically looks for the DB in the AppData folder of the Web Application.&lt;br /&gt;&lt;br /&gt;However there is a limitation that if the user is not a administrator, he would still not be able to AutoAttach the DB. we can solve this by using "User instances".&lt;br /&gt;User instance is another SQL server instance and runs under the credentials of the currently logged in user, thus no need to give the user administrative privileges.&lt;br /&gt;==================================================&lt;br /&gt;User Instances is a feature that makes SQL Server 2005 Express different from other SQL Server editions. Before I explain User Instances, you need to understand that a SQL Server instance is essentially an in-memory occurrence of the sqlservr.exe executable program. Different SQL Server editions support different numbers of instances. For example, the SQL Server 2005 Enterprise Edition supports 50 instances, and the SQL Server 2005 Standard, Workgroup, and Express editions each support 16 instances. Each instance runs separately and has its own set of databases that aren't shared by any other instance. Client applications connect to each instance by using the instance name.&lt;br /&gt;&lt;br /&gt;Typically, the first SQL Server instance you install becomes the "default" instance. The default instance uses the name of the computer on which it's installed. You can assign a name to subsequent instance installations, so they're called "named" instances. During the installation process, you can assign any name to a named instance. Client applications that want to connect to an instance use the \ convention. For example, if the default instance name is SQLServer1 and the instance name is MyInstance, the client application would connect to the named instance by using the server name SQLServer1\MyInstance.&lt;br /&gt;&lt;br /&gt;As with the other SQL Server editions, SQL Server Express supports the default instance and named instances, but SQL Server Express uses SQLExpress as the default instance name rather than the name of the computer system.&lt;br /&gt;&lt;br /&gt;In addition to regular SQL Server instances, SQL Server Express also supports User Instances. User instances are similar to named instances, but SQL Server Express creates user instances dynamically, and these instances have different limitations. When you install SQL Server Express, you have the option of enabling User Instances. By default, User Instances aren't enabled. After installation, you can enter the sp_configure command in SQL Server Management Studio Express (SSMSE) or the sqlcmd tool by using the following syntax:&lt;br /&gt;&lt;br /&gt;sp_configure 'user instances enabled','1'&lt;br /&gt;&lt;br /&gt;To disable User Instance support, replace 1 with a 0 in the sp_configure command.&lt;br /&gt;&lt;br /&gt;User Instances were designed to make deploying databases along with applications easier. User Instances let users create a database instance on demand even if they don't have administrative rights. To utilize User Instances, the application's connection string needs to use the attachdbfilename and user instance keywords as follows:&lt;br /&gt;&lt;br /&gt;Data Source=.\SQLExpress;integrated security=true;&lt;br /&gt;attachdbfilename=\MyDatabase.mdf;user instance=true;"&lt;br /&gt;&lt;br /&gt;When an application opens a connection to a SQL Server Express database in which User Instances are enabled and the application uses the attachdbfilename and user instance keywords, SQL Server Express copies the master and msdb databases to the user's directory. SQL Server Express starts a new instance of the sqlserver.exe program and SQL Server Express attaches the database named in the attachdbfilename keyword to the new instance.&lt;br /&gt;&lt;br /&gt;Unlike common SQL Server instances, SQL Server Express User Instances have some limitations. User Instances don't allow network connections, only local connections. As you might expect with the network-access restriction, User Instances don't support replication or distributed queries to remote databases. In addition, Windows integrated authentication is required. For more information about SQL Server Express and User Instances you can read the Microsoft article "SQL Server 2005 Express Edition User Instances" at&lt;br /&gt;http://msdn.microsoft.com/sql/express/default.aspx?pull=/library/en-us/dnsse/html/sqlexpuserinst.asp&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-7279401154109620077?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/7279401154109620077/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=7279401154109620077' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/7279401154109620077'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/7279401154109620077'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2007/12/sql-server-user-instances-and.html' title='SQL Server (user) instances and AutoAttach DB'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-4898984044354559028</id><published>2007-12-09T20:10:00.000-05:00</published><updated>2008-10-13T18:34:13.894-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sql2005'/><title type='text'>SQL Tips</title><content type='html'>Difference between truncate and delete&lt;br /&gt;&lt;ul&gt;&lt;li&gt;delete operations are logged and thus can be restored using transaction log backups (if not using Simple recovery model - the default)&lt;/li&gt;&lt;li&gt;truncate operations are not logged, thus cannot be rolled back.&lt;/li&gt;&lt;li&gt;delete can be used with WHERE clause to selectively delete rows&lt;/li&gt;&lt;li&gt;truncate cannot selectively delete rows.&lt;/li&gt;&lt;li&gt;truncate reseeds the identity column , delete does not reseed&lt;/li&gt;&lt;li&gt;truncate cannot be used on tables with foreign key constraints&lt;/li&gt;&lt;li&gt;since truncate is not logged, it does not activate triggers, delete does activate triggers&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;=====================================================&lt;br /&gt;Difference between temp table and table variables:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;table variables are not logged, i.e. they don't use transaction logs, thus cannot participate in transactions&lt;/li&gt;&lt;li&gt;indexes cannot be created on table variables&lt;/li&gt;&lt;li&gt;foreign key constraints cannot be created either on table variables or temp tables&lt;/li&gt;&lt;li&gt;table variables cannot be nested, i.e. they cannot be reused within the nested subquery, whereas temp tables can be accessed from within nested subqueries&lt;/li&gt;&lt;li&gt;SP with table variables require fewer recompilation than SP with temp tables.&lt;/li&gt;&lt;li&gt;table variables dont make use of parallelism since they reside in memory, temp table do make use of multiple processors since they reside in tempdb.&lt;/li&gt;&lt;li&gt;table variables used for small amounts of data since they reside in memory.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;=====================================================&lt;br /&gt;Types of Data Integrity&lt;br /&gt;Entity Integrity: Primary Key and Unique key constraints are used to maintain entity integrity&lt;br /&gt;Domain Integrity : Check and Not NULL constraints are used to maintain domain integrity&lt;br /&gt;Referential integrity : Foreign key constraints are used to maintain referential integrity&lt;br /&gt;=====================================================&lt;br /&gt;Local Temp tables &amp;amp; variables : exist for the duration of session, thus not shared by different client sessions. If Dynamic sql creates the local temp table then it falls out of scope as soon as it exits the EXEC statement used to execute the dynamic SQL.&lt;br /&gt;Global Temp tables &amp;amp; variables : shared by all client sessions and are destroyed when the last client session exits&lt;br /&gt;===========================================================&lt;br /&gt;Types of UDFs:&lt;br /&gt;Scalar valued udf : returns a single value, can be used anywhere an expression is used, just like subqueries.&lt;br /&gt;table valued udf : returns a table.&lt;br /&gt;2 types of table valued udf's :&lt;br /&gt;&lt;ul&gt;&lt;li&gt;inline table valued udf : uses a single statement to return a table&lt;/li&gt;&lt;li&gt;multi-statement table valued udf : multiple statements are issued in the udf before returning the table&lt;/li&gt;&lt;/ul&gt;UDF's can be used within select/having/where clauses and table valued udf's return rowsets/table and can be used in joins.&lt;br /&gt;Cannot use temp tables in UDF's, only table variables.&lt;br /&gt;UDFs are analogous to views that accept input parameters&lt;br /&gt;================================================&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Indexed Views &lt;/span&gt;are views that use disk space to store data.&lt;br /&gt;Created with SCHEMABINDING option&lt;br /&gt;have restrictions on the columns that the Indexed view can contain&lt;br /&gt;have restrictions on the columns that can be used within the index created for the view&lt;br /&gt;represent views that have a unique clustered index&lt;br /&gt;Must have ansi_nulls, quoted_identifier, arithabort etc session options set to ON&lt;br /&gt;If using &lt;span style="font-weight: bold;"&gt;standard edition&lt;/span&gt; than cannot be used implicitly by queries, must use the NOEXPAND optimizer HINT or reference with view with the VIEW name.&lt;br /&gt;If using &lt;span style="font-weight: bold;"&gt;Group by&lt;/span&gt; then count_big(*) must be used&lt;br /&gt;Must not be used in OLTP environments, suitable for less frequently updated base tables.&lt;br /&gt;&lt;br /&gt;============================================================&lt;br /&gt;ANSI_NULLS : default OFF, when ON then returns 0 rows when col = null or col &lt;&gt; null used even though the column has both null and not null values.&lt;br /&gt;Thus we need to insure that we use the col is null, col is not null syntax for comparisons&lt;br /&gt;&lt;br /&gt;ANSI_WARNINGS : default OFF: when ON then shows warnings when one of the following situations arises:&lt;br /&gt;sum, max, min, avg used against a column that contains nulls&lt;br /&gt;Divide by Zero exception occurs&lt;br /&gt;Overflow exception occurs (string may be truncated)&lt;br /&gt;&lt;br /&gt;QUOTED_IDENTIFIER : default OFF : when ON then allows object identifiers to use double quotes for distinguishing from reserved words and allows string literals to use single quotes&lt;br /&gt;&lt;br /&gt;Indexed views need all the above sessions options to be set to ON&lt;br /&gt;&lt;br /&gt;Concat_NULL_YIELDS NULL : default OFF&lt;br /&gt;&lt;br /&gt;ANSI_DEFAULTS : default OFF: When ON then sets the above and the following session options to ON:&lt;br /&gt;ANSI_PADDING&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-4898984044354559028?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/4898984044354559028/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=4898984044354559028' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/4898984044354559028'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/4898984044354559028'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2007/12/sql-tips.html' title='SQL Tips'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-3749278806594549574</id><published>2007-12-05T16:42:00.000-05:00</published><updated>2007-12-09T21:02:22.580-05:00</updated><title type='text'>More on MSMQ</title><content type='html'>Recoverable messages:&lt;br /&gt;&lt;br /&gt;MSMQ messages are stored in memory by default, hence there is a possibility of loosing them if the appdomain exits or the application crashes.&lt;br /&gt;To create messages that get persisted to disk we use Recoverable messages.&lt;br /&gt;&lt;br /&gt;Method 1:&lt;br /&gt;Set the &lt;span style="font-weight: bold;"&gt;Recoverable &lt;/span&gt;property on the Message itself before sending it.&lt;br /&gt;&lt;br /&gt;&lt;!-- {\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red43\green145\blue175;\red0\green0\blue255;\red163\green21\blue21;}??\fs20             \cf3 Message\cf0  recoverableMessage = \cf4 new\cf0  \cf3 Message\cf0 ();\par ??            recoverableMessage.Body = \cf5 "Sample Recoverable Message"\cf0 ;\par ??            recoverableMessage.Recoverable = \cf4 true\cf0 ;} --&gt; &lt;div    style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Courier New;font-size:10pt;color:black;"&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;Message&lt;/span&gt;&lt;span style="font-size:85%;"&gt; recoverableMessage = &lt;/span&gt;&lt;span style="font-size:85%;color:blue;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;Message&lt;/span&gt;&lt;span style="font-size:85%;"&gt;();&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;recoverableMessage.Body = &lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);font-size:85%;" &gt;"Sample Recoverable Message"&lt;/span&gt;&lt;span style="font-size:85%;"&gt;;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;recoverableMessage.Recoverable = &lt;/span&gt;&lt;span style="font-size:85%;color:blue;"&gt;true&lt;/span&gt;&lt;span style="font-size:85%;"&gt;;&lt;/span&gt;&lt;/p&gt; &lt;/div&gt;&lt;br /&gt;Method 2:&lt;br /&gt;Use the "&lt;span style="font-weight: bold;"&gt;DefaultPropertiesToSend&lt;/span&gt;.Recoverable" property on MessageQueue itself to mark all messages sent via this queue as recoverable:&lt;br /&gt;&lt;!-- {\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red43\green145\blue175;\red0\green0\blue255;\red163\green21\blue21;}??\fs20             \cf3 MessageQueue\cf0  msgQ = \cf4 new\cf0  \cf3 MessageQueue\cf0 (\cf5 @".\\private$\\Orders"\cf0 );\par ??            msgQ.DefaultPropertiesToSend.Recoverable = \cf4 true\cf0 ;\par ??            msgQ.Send(\cf5 "This message will be marked as Recoverable"\cf0 );} --&gt; &lt;div    style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Courier New;font-size:10pt;color:black;"&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;MessageQueue&lt;/span&gt;&lt;span style="font-size:85%;"&gt; msgQ = &lt;/span&gt;&lt;span style="font-size:85%;color:blue;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;MessageQueue&lt;/span&gt;&lt;span style="font-size:85%;"&gt;(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);font-size:85%;" &gt;@".\private$\Orders"&lt;/span&gt;&lt;span style="font-size:85%;"&gt;);&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;msgQ.DefaultPropertiesToSend.Recoverable = &lt;/span&gt;&lt;span style="font-size:85%;color:blue;"&gt;true&lt;/span&gt;&lt;span style="font-size:85%;"&gt;;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;msgQ.Send(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);font-size:85%;" &gt;"This message will be marked as Recoverable"&lt;/span&gt;&lt;span style="font-size:85%;"&gt;);&lt;/span&gt;&lt;/p&gt; &lt;/div&gt;  =====================================================&lt;br /&gt;Transactional Messages (Internal transactions)&lt;br /&gt;&lt;!-- {\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red43\green145\blue175;\red0\green0\blue255;\red163\green21\blue21;}??\fs20             \cf3 MessageQueueTransaction\cf0  msgTx = \cf4 new\cf0  \cf3 MessageQueueTransaction\cf0 ();\par ??            \cf3 MessageQueue\cf0  msgQ = \cf4 new\cf0  \cf3 MessageQueue\cf0 (\cf5 @".\\private$\\Orders"\cf0 );\par ??            msgTx.Begin();\par ??            \cf4 try\par ??\cf0             \{\par ??                msgQ.Send(\cf5 "First Message"\cf0 , msgTx);\par ??                msgQ.Send(\cf5 "Second Message"\cf0 , msgTx);\par ??                msgTx.Commit();\par ??\par ??                msgTx.Begin();\par ??                \cf3 Message\cf0  msg = msgQ.Receive(msgTx);\par ??                msgTx.Commit();\par ??            \}\par ??            \cf4 catch\par ??\cf0             \{\par ??                msgTx.Abort();\par ??            \}\par ??            \cf4 finally\par ??\cf0             \{\par ??                msgQ.Close();\par ??            \}} --&gt; &lt;div    style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Courier New;font-size:10pt;color:black;"&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;MessageQueueTransaction&lt;/span&gt;&lt;span style="font-size:85%;"&gt; msgTx = &lt;/span&gt;&lt;span style="font-size:85%;color:blue;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;MessageQueueTransaction&lt;/span&gt;&lt;span style="font-size:85%;"&gt;();&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;MessageQueue&lt;/span&gt;&lt;span style="font-size:85%;"&gt; msgQ = &lt;/span&gt;&lt;span style="font-size:85%;color:blue;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;MessageQueue&lt;/span&gt;&lt;span style="font-size:85%;"&gt;(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);font-size:85%;" &gt;@".\private$\Orders"&lt;/span&gt;&lt;span style="font-size:85%;"&gt;);&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;msgTx.Begin();&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;color:blue;"&gt;try&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;{&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;  msgQ.Send(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);font-size:85%;" &gt;"First Message"&lt;/span&gt;&lt;span style="font-size:85%;"&gt;, msgTx);&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;  msgQ.Send(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);font-size:85%;" &gt;"Second Message"&lt;/span&gt;&lt;span style="font-size:85%;"&gt;, msgTx);&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;  msgTx.Commit();&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt; &lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;  msgTx.Begin();&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;  &lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;Message&lt;/span&gt;&lt;span style="font-size:85%;"&gt; msg = msgQ.Receive(msgTx);&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;  msgTx.Commit();&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt; }&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt; &lt;span style="font-size:85%;color:blue;"&gt;catch&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt; {&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;   msgTx.Abort();&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt; }&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt; &lt;span style="font-size:85%;color:blue;"&gt;finally&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt; {&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;   msgQ.Close();&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt; }&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;================================================================&lt;/p&gt;&lt;p style="margin: 0px;"&gt;External Transactions (using MSDTC and COM+)&lt;/p&gt;&lt;p style="margin: 0px;"&gt;====================================================================&lt;/p&gt;&lt;p style="margin: 0px;"&gt; &lt;!-- {\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red0\green0\blue0;\red43\green145\blue175;\red163\green21\blue21;\red0\green128\blue0;}??\fs20 \cf1 using\cf0  System.EnterpriseServices;\par ??\cf1 using\cf0  System.Reflection;\par ??\cf1 using\cf0  System.Messaging;\par ??\cf1 using\cf0  System.Data.SqlClient;\par ??\par ??[assembly: \cf4 ApplicationName\cf0 (\cf5 "MSMQ_Example"\cf0 )]\par ??[assembly: \cf4 ApplicationActivation\cf0 (\cf4 ActivationOption\cf0 .Server)]\par ??\par ??[\cf4 Transaction\cf0 (\cf4 TransactionOption\cf0 .Required)]\par ??\cf1 public\cf0  \cf1 class\cf0  \cf4 Message\par ??\cf0 \{\par ??    [\cf4 AutoComplete\cf0 ()]\par ??    \cf1 public\cf0  \cf1 void\cf0  DoTransaction()\par ??    \{\par ??        \cf6 //Create the queue\par ??\cf0         \cf4 MessageQueue\cf0  msgQ = \cf1 new\cf0  \cf4 MessageQueue\cf0 (\cf5 @".\\private$\\Orders"\cf0 );\par ??        Order incomingOrder;\par ??        \cf6 //Configure the formatter with the expected type(s)\par ??\cf0         \cf4 Type\cf0 [] targetTypes = \cf1 new\cf0  \cf4 Type\cf0 [1];\par ??        targetTypes[0] = \cf1 typeof\cf0 (Order);\par ??        msgQ.Formatter = \cf1 new\cf0  \cf4 XmlMessageFormatter\cf0 (targetTypes);\par ??        \cf6 //DB Connection setup code removed\par ??\cf0         \cf4 SqlConnection\cf0  sqlConn = \cf1 new\cf0  \cf4 SqlConnection\cf0 (connectionString);\par ??        \cf4 SqlCommand\cf0  insertLog = \cf1 new\cf0  \cf4 SqlCommand\cf0 (sqlString, sqlConn);\par ??        \cf6 //Command setup code removed\par ??\cf0         \cf1 try\par ??\cf0         \{\par ??            \cf6 //Receive new message, casting the result to the Order type\par ??\cf0             incomingOrder = (Order)(msgQ.Receive(\cf1 new\cf0  \cf4 TimeSpan\cf0 (0, 0, 30)).Body);\par ??            \cf6 //Use ID from message to setup parameters for database insert\par ??\cf0             orderIDParam.Value = incomingOrder.ID;\par ??            receiveParam.Value = \cf4 DateTime\cf0 .Now;\par ??            insertLog.Parameters.Add(orderIDParam);\par ??            insertLog.Parameters.Add(receiveParam);\par ??            sqlConn.Open();\par ??            \cf6 //Insert a new entry into the Log table\par ??\cf0             insertLog.ExecuteNonQuery();\par ??            \cf6 //Mark the transaction as completing successfully... can be done using ContextUtil.SetComplete\par ??\cf0         \}\par ??        \cf1 catch\cf0  (\cf4 Exception\cf0  ex)\par ??        \{\par ??            \cf6 //Remember to throw the exception, only then will AutoComplete() abort the transaction\par ??\cf0             \cf6 // transaction can be aborted using ContextUtil.Abort if AutoComplete() atribute is not used\par ??\cf0             \cf1 throw\cf0  ex;\par ??        \}\par ??        \cf1 finally\par ??\cf0         \{\par ??            \cf6 //Always close the connection, regardless of success/failure\par ??\cf0             sqlConn.Close();\par ??        \}\par ??    \}\par ??\}} --&gt; &lt;/p&gt;&lt;div    style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Courier New;font-size:10pt;color:black;"&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;color:blue;"&gt;using&lt;/span&gt;&lt;span style="font-size:85%;"&gt; System.EnterpriseServices;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;color:blue;"&gt;using&lt;/span&gt;&lt;span style="font-size:85%;"&gt; System.Messaging;&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin: 0px;"&gt; &lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;[assembly: &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;ApplicationName&lt;/span&gt;&lt;span style="font-size:85%;"&gt;(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);font-size:85%;" &gt;"MSMQ_Example"&lt;/span&gt;&lt;span style="font-size:85%;"&gt;)]&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;[assembly: &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;ApplicationActivation&lt;/span&gt;&lt;span style="font-size:85%;"&gt;(&lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;ActivationOption&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.Server)]&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt; &lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;[&lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;Transaction&lt;/span&gt;&lt;span style="font-size:85%;"&gt;(&lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;TransactionOption&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.Required)]&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;color:blue;"&gt;public&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:blue;"&gt;class&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;Message&lt;/span&gt;&lt;span style="font-size:85%;"&gt; : &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;ServicedComponent&lt;/span&gt;&lt;/p&gt;&lt;div style="background: white none repeat scroll 0% 50%; font-family: Courier New; font-size: 10pt; color: black; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;  &lt;/div&gt;   &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;{&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;    [&lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;AutoComplete&lt;/span&gt;&lt;span style="font-size:85%;"&gt;()]&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;    &lt;span style="font-size:85%;color:blue;"&gt;public&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:blue;"&gt;void&lt;/span&gt;&lt;span style="font-size:85%;"&gt; DoTransaction()&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;    {&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;        &lt;span style="font-size:85%;color:green;"&gt;//Create the queue&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;MessageQueue&lt;/span&gt;&lt;span style="font-size:85%;"&gt; msgQ = &lt;/span&gt;&lt;span style="font-size:85%;color:blue;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;MessageQueue&lt;/span&gt;&lt;span style="font-size:85%;"&gt;(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);font-size:85%;" &gt;@".\private$\Orders"&lt;/span&gt;&lt;span style="font-size:85%;"&gt;);&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;        Order incomingOrder;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;        &lt;span style="font-size:85%;color:green;"&gt;//Configure the formatter with the expected type(s)&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;Type&lt;/span&gt;&lt;span style="font-size:85%;"&gt;[] targetTypes = &lt;/span&gt;&lt;span style="font-size:85%;color:blue;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;Type&lt;/span&gt;&lt;span style="font-size:85%;"&gt;[1];&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;        targetTypes[0] = &lt;/span&gt;&lt;span style="font-size:85%;color:blue;"&gt;typeof&lt;/span&gt;&lt;span style="font-size:85%;"&gt;(Order);&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;        msgQ.Formatter = &lt;/span&gt;&lt;span style="font-size:85%;color:blue;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;XmlMessageFormatter&lt;/span&gt;&lt;span style="font-size:85%;"&gt;(targetTypes);&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;        &lt;span style="font-size:85%;color:green;"&gt;//DB Connection setup code removed&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;SqlConnection&lt;/span&gt;&lt;span style="font-size:85%;"&gt; sqlConn = &lt;/span&gt;&lt;span style="font-size:85%;color:blue;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;SqlConnection&lt;/span&gt;&lt;span style="font-size:85%;"&gt;(connectionString);&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;SqlCommand&lt;/span&gt;&lt;span style="font-size:85%;"&gt; insertLog = &lt;/span&gt;&lt;span style="font-size:85%;color:blue;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;SqlCommand&lt;/span&gt;&lt;span style="font-size:85%;"&gt;(sqlString, sqlConn);&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;        &lt;span style="font-size:85%;color:green;"&gt;//Command setup code removed&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;        &lt;span style="font-size:85%;color:blue;"&gt;try&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;        {&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;            &lt;span style="font-size:85%;color:green;"&gt;//Receive new message, casting the result to the Order type&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;            incomingOrder = (Order)(msgQ.Receive(&lt;/span&gt;&lt;span style="font-size:85%;color:blue;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;TimeSpan&lt;/span&gt;&lt;span style="font-size:85%;"&gt;(0, 0, 30)).Body);&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;            &lt;span style="font-size:85%;color:green;"&gt;//Use ID from message to setup parameters for database insert&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;            orderIDParam.Value = incomingOrder.ID;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;            receiveParam.Value = &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;DateTime&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.Now;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;            insertLog.Parameters.Add(orderIDParam);&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;            insertLog.Parameters.Add(receiveParam);&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;            sqlConn.Open();&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;            &lt;span style="font-size:85%;color:green;"&gt;//Insert a new entry into the Log table&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;            insertLog.ExecuteNonQuery();&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;            &lt;span style="font-size:85%;color:green;"&gt;//Mark the transaction as completing successfully... can be done using ContextUtil.SetComplete&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;        }&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;        &lt;span style="font-size:85%;color:blue;"&gt;catch&lt;/span&gt;&lt;span style="font-size:85%;"&gt; (&lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;Exception&lt;/span&gt;&lt;span style="font-size:85%;"&gt; ex)&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;        {&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;            &lt;span style="font-size:85%;color:green;"&gt;//Remember to throw the exception, only then will AutoComplete() abort the transaction&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;            &lt;span style="font-size:85%;color:green;"&gt;// transaction can be aborted using ContextUtil.Abort if AutoComplete() atribute is not used&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;            &lt;span style="font-size:85%;color:blue;"&gt;throw&lt;/span&gt;&lt;span style="font-size:85%;"&gt; ex;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;        }&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;        &lt;span style="font-size:85%;color:blue;"&gt;finally&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;        {&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;            &lt;span style="font-size:85%;color:green;"&gt;//Always close the connection, regardless of success/failure&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;            sqlConn.Close();&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;        }&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;    }&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;}&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p style="margin: 0px;"&gt;After you create the serviced component, it must be strongly named and then deployed to the GAC so as to work correctly as a COM+ application.&lt;/p&gt;&lt;br /&gt;&lt;p style="margin: 0px;"&gt;After the component has been installed into the COM+ application, clients can create and call your component just like any other .NET class, and your component will automatically run inside COM+ and act as part of a transaction.&lt;/p&gt; &lt;/div&gt;   &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-3749278806594549574?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/3749278806594549574/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=3749278806594549574' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/3749278806594549574'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/3749278806594549574'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2007/12/more-on-msmq.html' title='More on MSMQ'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-2843859151760189277</id><published>2007-12-05T11:06:00.000-05:00</published><updated>2008-11-13T06:04:45.054-05:00</updated><title type='text'>MSMQ Primer</title><content type='html'>Creating Queues and Managing Queues is a breeze with .NET&lt;br /&gt;Queuenames in .NET:&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_VjiZepP-keA/R1bND5ZMNWI/AAAAAAAAADA/-beKBvsnmLY/s1600-h/queue_names.gif"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://4.bp.blogspot.com/_VjiZepP-keA/R1bND5ZMNWI/AAAAAAAAADA/-beKBvsnmLY/s320/queue_names.gif" alt="" id="BLOGGER_PHOTO_ID_5140521491519780194" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;public queues : .\qname&lt;br /&gt;private : .\private$\qname&lt;br /&gt;journal:   .\qname\journal$&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Create queues using the MessageQueue class and specify if you need to use Journal queues with the message queue. the Journal queues hold the messages after that have been "received" from the main message queue.&lt;br /&gt;The third type of queues are the AdministrationQueues /Acnowledgement queues and we use the Message.RecieveByCorrelationId method or PeekByCorrelationId to receive admin/ack messages from these queues after a message has been received from the main message queue.&lt;br /&gt;the PeekByCorrelationId method takes in the message id of the message in the main message queue.&lt;br /&gt;&lt;!-- {\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red163\green21\blue21;}??\fs20     \cf3 public\cf0  \cf3 class\cf0  \cf4 QueueMgmt\par ??\cf0     \{\par ??        \cf3 public\cf0  \cf3 static\cf0  \cf4 MessageQueue\cf0  CreateQueue(\cf3 string\cf0  path)\par ??        \{\par ??            \cf4 MessageQueue\cf0  mq = \cf3 null\cf0 ;\par ??            \cf3 if\cf0  (\cf4 MessageQueue\cf0 .Exists(path))\par ??            \{\par ??                mq = \cf3 new\cf0  \cf4 MessageQueue\cf0 (path);\par ??                \cf4 Console\cf0 .WriteLine(\cf5 "Connected to existing queue "\cf0  + path);\par ??            \}\par ??            \cf3 else\par ??\cf0             \{\par ??                mq = \cf4 MessageQueue\cf0 .Create(path);\par ??                \cf4 Console\cf0 .WriteLine(\cf5 "Created to new queue "\cf0  + path);\par ??            \}\par ??            \cf4 Console\cf0 .WriteLine(\cf5 "Message Queue format is "\cf0  + mq.FormatName);\par ??            \cf3 return\cf0  mq;\par ??        \}\par ??    \}} --&gt; &lt;div    style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Courier New;font-size:10pt;color:black;"&gt; &lt;!-- {\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red163\green21\blue21;}??\fs20     \cf3 public\cf0  \cf3 class\cf0  \cf4 QueueMgmt\par ??\cf0     \{\par ??        \cf3 public\cf0  \cf3 static\cf0  \cf4 MessageQueue\cf0  CreateQueue(\cf3 string\cf0  path)\par ??        \{\par ??            \cf4 MessageQueue\cf0  mq = \cf3 null\cf0 ;\par ??            \cf3 if\cf0  (\cf4 MessageQueue\cf0 .Exists(path))\par ??            \{\par ??                mq = \cf3 new\cf0  \cf4 MessageQueue\cf0 (path);\par ??                \cf4 Console\cf0 .WriteLine(\cf5 "Connected to existing queue "\cf0  + path);\par ??            \}\par ??            \cf3 else\par ??\cf0             \{\par ??                mq = \cf4 MessageQueue\cf0 .Create(path);\par ??                \cf4 Console\cf0 .WriteLine(\cf5 "Created to new queue "\cf0  + path);\par ??            \}\par ??            \cf4 Console\cf0 .WriteLine(\cf5 "Message Queue format is "\cf0  + mq.FormatName);\par ??            \cf3 return\cf0  mq;\par ??        \}\par ??    \}} --&gt; &lt;div    style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Courier New;font-size:10pt;color:black;"&gt; &lt;p style="margin: 0px;"&gt;    &lt;span style="font-size:85%;color:blue;"&gt;public&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:blue;"&gt;class&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;QueueMgmt&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;    {&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;        &lt;span style="font-size:85%;color:blue;"&gt;public&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:blue;"&gt;static&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;MessageQueue&lt;/span&gt;&lt;span style="font-size:85%;"&gt; CreateQueue(&lt;/span&gt;&lt;span style="font-size:85%;color:blue;"&gt;string&lt;/span&gt;&lt;span style="font-size:85%;"&gt; path)&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;        {&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;            &lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;MessageQueue&lt;/span&gt;&lt;span style="font-size:85%;"&gt; mq = &lt;/span&gt;&lt;span style="font-size:85%;color:blue;"&gt;null&lt;/span&gt;&lt;span style="font-size:85%;"&gt;;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;            &lt;span style="font-size:85%;color:blue;"&gt;if&lt;/span&gt;&lt;span style="font-size:85%;"&gt; (&lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;MessageQueue&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.Exists(path))&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;            {&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;                mq = &lt;/span&gt;&lt;span style="font-size:85%;color:blue;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;MessageQueue&lt;/span&gt;&lt;span style="font-size:85%;"&gt;(path);&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;                &lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;Console&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.WriteLine(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);font-size:85%;" &gt;"Connected to existing queue "&lt;/span&gt;&lt;span style="font-size:85%;"&gt; + path);&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;            }&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;            &lt;span style="font-size:85%;color:blue;"&gt;else&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;            {&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;                mq = &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;MessageQueue&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.Create(path);&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;                &lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;Console&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.WriteLine(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);font-size:85%;" &gt;"Created to new queue "&lt;/span&gt;&lt;span style="font-size:85%;"&gt; + path);&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;            }&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;            &lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;Console&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.WriteLine(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);font-size:85%;" &gt;"Message Queue format is "&lt;/span&gt;&lt;span style="font-size:85%;"&gt; + mq.FormatName);&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;            &lt;span style="font-size:85%;color:blue;"&gt;return&lt;/span&gt;&lt;span style="font-size:85%;"&gt; mq;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;        }&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;    }&lt;/span&gt;&lt;/p&gt; &lt;/div&gt;  &lt;/div&gt;&lt;span style="font-size:85%;"&gt;  =========================================================&lt;br /&gt;&lt;/span&gt;&lt;!-- {\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red0\green128\blue0;\red163\green21\blue21;}??\fs20         \cf3 private\cf0  \cf3 void\cf0  btnCreateQueue_Click(\cf3 object\cf0  sender, \cf4 EventArgs\cf0  e)\par ??        \{\par ??            \cf5 // Create a public queue and configure it for journaling.\par ??\cf0             \cf3 using\cf0  (\cf4 MessageQueue\cf0  mq = \cf4 QueueMgmt\cf0 .CreateQueue(\cf6 @".\\DotNet"\cf0 ))\par ??            \{\par ??                mq.Label = \cf6 "DotNet Message Queue"\cf0 ;\par ??                mq.UseJournalQueue = \cf3 true\cf0 ;\par ??            \} \cf5 // mq disposed.\par ??\cf0             \cf5 // Create a private queue for acknowledgments.\par ??\cf0             \cf3 using\cf0  (\cf4 MessageQueue\cf0  mq = \cf4 QueueMgmt\cf0 .CreateQueue(\cf6 @".\\Private$\\DotNetAdmin"\cf0 ))\par ??            \{\par ??                mq.Label = \cf6 "DotNet Acknowledge Queue"\cf0 ;\par ??            \} \cf5 // mq disposed.\par ??\cf0         \}} --&gt; &lt;div    style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Courier New;font-size:10pt;color:black;"&gt; &lt;p style="margin: 0px;"&gt;        &lt;span style="font-size:85%;color:blue;"&gt;private&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:blue;"&gt;void&lt;/span&gt;&lt;span style="font-size:85%;"&gt; btnCreateQueue_Click(&lt;/span&gt;&lt;span style="font-size:85%;color:blue;"&gt;object&lt;/span&gt;&lt;span style="font-size:85%;"&gt; sender, &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;EventArgs&lt;/span&gt;&lt;span style="font-size:85%;"&gt; e)&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;        {&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;            &lt;span style="font-size:85%;color:green;"&gt;// Create a public queue and configure it for journaling.&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;            &lt;span style="font-size:85%;color:blue;"&gt;using&lt;/span&gt;&lt;span style="font-size:85%;"&gt; (&lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;MessageQueue&lt;/span&gt;&lt;span style="font-size:85%;"&gt; mq = &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;QueueMgmt&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.CreateQueue(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);font-size:85%;" &gt;@".\DotNet"&lt;/span&gt;&lt;span style="font-size:85%;"&gt;))&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;            {&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;                mq.Label = &lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);font-size:85%;" &gt;"DotNet Message Queue"&lt;/span&gt;&lt;span style="font-size:85%;"&gt;;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;                mq.UseJournalQueue = &lt;/span&gt;&lt;span style="font-size:85%;color:blue;"&gt;true&lt;/span&gt;&lt;span style="font-size:85%;"&gt;;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;            } &lt;/span&gt;&lt;span style="font-size:85%;color:green;"&gt;// mq disposed.&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;            &lt;span style="font-size:85%;color:green;"&gt;// Create a private queue for acknowledgments.&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;            &lt;span style="font-size:85%;color:blue;"&gt;using&lt;/span&gt;&lt;span style="font-size:85%;"&gt; (&lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;MessageQueue&lt;/span&gt;&lt;span style="font-size:85%;"&gt; mq = &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;QueueMgmt&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.CreateQueue(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);font-size:85%;" &gt;@".\Private$\DotNetAdmin"&lt;/span&gt;&lt;span style="font-size:85%;"&gt;))&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;            {&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;                mq.Label = &lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);font-size:85%;" &gt;"DotNet Acknowledge Queue"&lt;/span&gt;&lt;span style="font-size:85%;"&gt;;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;            } &lt;/span&gt;&lt;span style="font-size:85%;color:green;"&gt;// mq disposed.&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;        }&lt;/span&gt;&lt;/p&gt; &lt;/div&gt;&lt;br /&gt;=======================================&lt;br /&gt;After creating the queues, you can send messages to the queue using mq.Send method, note we can send any XML Serializable types in the message body. Remember to set the mq.Formatter.TargetTypes property with the TYPES that it is supposed to deserialize when receiving them.&lt;br /&gt;&lt;br /&gt;Note we are also setting the Administration queue which will receive the acknowledgment messages once they are read from the Queue.&lt;br /&gt;&lt;br /&gt;&lt;!-- {\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red163\green21\blue21;}??\fs20         \cf3 private\cf0  \cf3 void\cf0  btnSendMessage_Click(\cf3 object\cf0  sender, \cf4 EventArgs\cf0  e)\par ??        \{\par ??            \cf3 using\cf0  (\cf4 MessageQueue\cf0  mq = \cf3 new\cf0  \cf4 MessageQueue\cf0 (\cf5 @".\\dotnet"\cf0 ))\par ??            \{\par ??                \cf3 using\cf0  (System.Messaging.\cf4 Message\cf0  msg = \cf3 new\cf0  System.Messaging.\cf4 Message\cf0 ())\par ??                \{\par ??                    msg.Label = \cf5 "dotnetmessage"\cf0 ;\par ??                    msg.Body = \cf5 "Message : "\cf0  + \cf4 DateTime\cf0 .Now.ToString();\par ??                    msg.AdministrationQueue = \cf3 new\cf0  \cf4 MessageQueue\cf0 (\cf5 @".\\private$\\dotnetadmin"\cf0 );\par ??                    msg.AcknowledgeType = \cf4 AcknowledgeTypes\cf0 .FullReceive;\par ??                    mq.Send(msg);\par ??                    \cf4 Console\cf0 .WriteLine(\cf5 "Message sent with ID: "\cf0  + msg.Id);\par ??                \}\par ??            \}\par ??        \}} --&gt; &lt;div    style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Courier New;font-size:10pt;color:black;"&gt; &lt;p style="margin: 0px;"&gt;        &lt;span style="font-size:85%;color:blue;"&gt;private&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:blue;"&gt;void&lt;/span&gt;&lt;span style="font-size:85%;"&gt; btnSendMessage_Click(&lt;/span&gt;&lt;span style="font-size:85%;color:blue;"&gt;object&lt;/span&gt;&lt;span style="font-size:85%;"&gt; sender, &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;EventArgs&lt;/span&gt;&lt;span style="font-size:85%;"&gt; e)&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;        {&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;            &lt;span style="font-size:85%;color:blue;"&gt;using&lt;/span&gt;&lt;span style="font-size:85%;"&gt; (&lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;MessageQueue&lt;/span&gt;&lt;span style="font-size:85%;"&gt; mq = &lt;/span&gt;&lt;span style="font-size:85%;color:blue;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;MessageQueue&lt;/span&gt;&lt;span style="font-size:85%;"&gt;(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);font-size:85%;" &gt;@".\dotnet"&lt;/span&gt;&lt;span style="font-size:85%;"&gt;))&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;            {&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;                &lt;span style="font-size:85%;color:blue;"&gt;using&lt;/span&gt;&lt;span style="font-size:85%;"&gt; (System.Messaging.&lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;Message&lt;/span&gt;&lt;span style="font-size:85%;"&gt; msg = &lt;/span&gt;&lt;span style="font-size:85%;color:blue;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; System.Messaging.&lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;Message&lt;/span&gt;&lt;span style="font-size:85%;"&gt;())&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;                {&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;                    msg.Label = &lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);font-size:85%;" &gt;"dotnetmessage"&lt;/span&gt;&lt;span style="font-size:85%;"&gt;;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;                    msg.Body = &lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);font-size:85%;" &gt;"Message : "&lt;/span&gt;&lt;span style="font-size:85%;"&gt; + &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;DateTime&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.Now.ToString();&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;                    msg.AdministrationQueue = &lt;/span&gt;&lt;span style="font-size:85%;color:blue;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;MessageQueue&lt;/span&gt;&lt;span style="font-size:85%;"&gt;(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);font-size:85%;" &gt;@".\private$\dotnetadmin"&lt;/span&gt;&lt;span style="font-size:85%;"&gt;);&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;                    msg.AcknowledgeType = &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;AcknowledgeTypes&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.FullReceive;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;                    mq.Send(msg);&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;                    &lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;Console&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.WriteLine(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);font-size:85%;" &gt;"Message sent with ID: "&lt;/span&gt;&lt;span style="font-size:85%;"&gt; + msg.Id);&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;                }&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;            }&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;        }&lt;/span&gt;&lt;/p&gt; &lt;/div&gt;&lt;br /&gt;==============================================&lt;br /&gt;Once the message is sent it arrives in the public or the private queue where it was sent.&lt;br /&gt;Then while receiving the messages we read the message from the public/private queue, once it has been received a copy is stored in the Journal queue if one has been setup.&lt;br /&gt;Also admin messages are sent to the Admin queue depending on the AcknowledgementTypes setup during the sending of the message.&lt;br /&gt;Note we can get mutiple ack/admin messages for a single message by ORing different ackTypes in the message.AcknowledgeType enumneration.&lt;br /&gt;&lt;br /&gt;&lt;!-- {\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red163\green21\blue21;}??\fs20         \cf3 private\cf0  \cf3 void\cf0  btnSendMessage_Click(\cf3 object\cf0  sender, \cf4 EventArgs\cf0  e)\par ??        \{\par ??            \cf3 using\cf0  (\cf4 MessageQueue\cf0  mq = \cf3 new\cf0  \cf4 MessageQueue\cf0 (\cf5 @".\\dotnet"\cf0 ))\par ??            \{\par ??                \cf3 using\cf0  (System.Messaging.\cf4 Message\cf0  msg = \cf3 new\cf0  System.Messaging.\cf4 Message\cf0 ())\par ??                \{\par ??                    msg.Label = \cf5 "dotnetmessage"\cf0 ;\par ??                    msg.Body = \cf5 "Message : "\cf0  + \cf4 DateTime\cf0 .Now.ToString();\par ??                    msg.AdministrationQueue = \cf3 new\cf0  \cf4 MessageQueue\cf0 (\cf5 @".\\private$\\dotnetadmin"\cf0 );\par ??                    msg.AcknowledgeType = \cf4 AcknowledgeTypes\cf0 .FullReceive;\par ??                    mq.Send(msg);\par ??                    \cf4 Console\cf0 .WriteLine(\cf5 "Message sent with ID: "\cf0  + msg.Id);\par ??                \}\par ??            \}\par ??        \}} --&gt; &lt;div    style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Courier New;font-size:10pt;color:black;"&gt; &lt;!-- {\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red163\green21\blue21;}??\fs20        \cf3 private\cf0  \cf3 void\cf0  btnReceive_Click(\cf3 object\cf0  sender, \cf4 EventArgs\cf0  e)\par ??        \{\par ??            \cf4 Type\cf0 [] targetTypes = \{ \cf3 typeof\cf0 (\cf3 string\cf0 ) \};\par ??            \cf3 string\cf0  msgId = \cf3 string\cf0 .Empty;\par ??\par ??            \cf3 using\cf0  (\cf4 MessageQueue\cf0  mq = \cf3 new\cf0  \cf4 MessageQueue\cf0 (\cf5 @".\\dotnet"\cf0 ))\par ??            \{\par ??                ((\cf4 XmlMessageFormatter\cf0 )mq.Formatter).TargetTypes = targetTypes;\par ??                \cf3 using\cf0  (System.Messaging.\cf4 Message\cf0  msg = mq.Receive())\par ??                \{\par ??                    \cf4 Console\cf0 .WriteLine(\cf5 "Received Message ID \{0\} : \\n\\t Body = \{1\}"\cf0 , msg.Id, msg.Body);\par ??                    msgId = msg.Id;\par ??                \}\par ??            \}\par ??\par ??            \cf3 using\cf0  (\cf4 MessageQueue\cf0  mq = \cf3 new\cf0  \cf4 MessageQueue\cf0 (\cf5 @".\\dotnet\\Journal$"\cf0 ))\par ??            \{\par ??                ((\cf4 XmlMessageFormatter\cf0 )mq.Formatter).TargetTypes = targetTypes;\par ??                \cf3 using\cf0  (System.Messaging.\cf4 Message\cf0  msg = mq.PeekById(msgId))\par ??                \{\par ??                    \cf4 Console\cf0 .WriteLine(\cf5 "Peeked message from Journal Queue \{0\}:\\n\\t Body = \{1\}"\cf0 , msg.Id, msg.Body);\par ??                \}\par ??            \}\par ??            \cf3 using\cf0  (\cf4 MessageQueue\cf0  mq = \cf3 new\cf0  \cf4 MessageQueue\cf0 (\cf5 @".\\private$\\dotnetadmin"\cf0 ))\par ??            \{\par ??                \cf3 using\cf0  (System.Messaging.\cf4 Message\cf0  msg = mq.PeekByCorrelationId(msgId))\par ??                \{\par ??                    \cf4 Console\cf0 .WriteLine(\cf5 "Peeked Acknowledgement queue \{0\} : \\n\\t Acknowledgement is \{1\}"\cf0 , msg.Id, msg.Acknowledgment);\par ??                \}\par ??            \}\par ??        \}} --&gt; &lt;div    style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Courier New;font-size:10pt;color:black;"&gt; &lt;p style="margin: 0px;"&gt;       &lt;span style="font-size:85%;color:blue;"&gt;private&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:blue;"&gt;void&lt;/span&gt;&lt;span style="font-size:85%;"&gt; btnReceive_Click(&lt;/span&gt;&lt;span style="font-size:85%;color:blue;"&gt;object&lt;/span&gt;&lt;span style="font-size:85%;"&gt; sender, &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;EventArgs&lt;/span&gt;&lt;span style="font-size:85%;"&gt; e)&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;        {&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;            &lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;Type&lt;/span&gt;&lt;span style="font-size:85%;"&gt;[] targetTypes = { &lt;/span&gt;&lt;span style="font-size:85%;color:blue;"&gt;typeof&lt;/span&gt;&lt;span style="font-size:85%;"&gt;(&lt;/span&gt;&lt;span style="font-size:85%;color:blue;"&gt;string&lt;/span&gt;&lt;span style="font-size:85%;"&gt;) };&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;            &lt;span style="font-size:85%;color:blue;"&gt;string&lt;/span&gt;&lt;span style="font-size:85%;"&gt; msgId = &lt;/span&gt;&lt;span style="font-size:85%;color:blue;"&gt;string&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.Empty;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt; &lt;/p&gt; &lt;p style="margin: 0px;"&gt;            &lt;span style="font-size:85%;color:blue;"&gt;using&lt;/span&gt;&lt;span style="font-size:85%;"&gt; (&lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;MessageQueue&lt;/span&gt;&lt;span style="font-size:85%;"&gt; mq = &lt;/span&gt;&lt;span style="font-size:85%;color:blue;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;MessageQueue&lt;/span&gt;&lt;span style="font-size:85%;"&gt;(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);font-size:85%;" &gt;@".\dotnet"&lt;/span&gt;&lt;span style="font-size:85%;"&gt;))&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;            {&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;                ((&lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;XmlMessageFormatter&lt;/span&gt;&lt;span style="font-size:85%;"&gt;)mq.Formatter).TargetTypes = targetTypes;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;                &lt;span style="font-size:85%;color:blue;"&gt;using&lt;/span&gt;&lt;span style="font-size:85%;"&gt; (System.Messaging.&lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;Message&lt;/span&gt;&lt;span style="font-size:85%;"&gt; msg = mq.Receive())&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;                {&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;                    &lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;Console&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.WriteLine(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);font-size:85%;" &gt;"Received Message ID {0} : \n\t Body = {1}"&lt;/span&gt;&lt;span style="font-size:85%;"&gt;, msg.Id, msg.Body);&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;                    msgId = msg.Id;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;                }&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;            }&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt; &lt;/p&gt; &lt;p style="margin: 0px;"&gt;            &lt;span style="font-size:85%;color:blue;"&gt;using&lt;/span&gt;&lt;span style="font-size:85%;"&gt; (&lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;MessageQueue&lt;/span&gt;&lt;span style="font-size:85%;"&gt; mq = &lt;/span&gt;&lt;span style="font-size:85%;color:blue;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;MessageQueue&lt;/span&gt;&lt;span style="font-size:85%;"&gt;(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);font-size:85%;" &gt;@".\dotnet\Journal$"&lt;/span&gt;&lt;span style="font-size:85%;"&gt;))&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;            {&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;                ((&lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;XmlMessageFormatter&lt;/span&gt;&lt;span style="font-size:85%;"&gt;)mq.Formatter).TargetTypes = targetTypes;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;                &lt;span style="font-size:85%;color:blue;"&gt;using&lt;/span&gt;&lt;span style="font-size:85%;"&gt; (System.Messaging.&lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;Message&lt;/span&gt;&lt;span style="font-size:85%;"&gt; msg = mq.PeekById(msgId))&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;                {&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;                    &lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;Console&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.WriteLine(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);font-size:85%;" &gt;"Peeked message from Journal Queue {0}:\n\t Body = {1}"&lt;/span&gt;&lt;span style="font-size:85%;"&gt;, msg.Id, msg.Body);&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;                }&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;            }&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;            &lt;span style="font-size:85%;color:blue;"&gt;using&lt;/span&gt;&lt;span style="font-size:85%;"&gt; (&lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;MessageQueue&lt;/span&gt;&lt;span style="font-size:85%;"&gt; mq = &lt;/span&gt;&lt;span style="font-size:85%;color:blue;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;MessageQueue&lt;/span&gt;&lt;span style="font-size:85%;"&gt;(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);font-size:85%;" &gt;@".\private$\dotnetadmin"&lt;/span&gt;&lt;span style="font-size:85%;"&gt;))&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;            {&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;                &lt;span style="font-size:85%;color:blue;"&gt;using&lt;/span&gt;&lt;span style="font-size:85%;"&gt; (System.Messaging.&lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;Message&lt;/span&gt;&lt;span style="font-size:85%;"&gt; msg = mq.PeekByCorrelationId(msgId))&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;                {&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;                    &lt;span style="color: rgb(43, 145, 175);font-size:85%;" &gt;Console&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.WriteLine(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);font-size:85%;" &gt;"Peeked Acknowledgement queue {0} : \n\t Acknowledgement is {1}"&lt;/span&gt;&lt;span style="font-size:85%;"&gt;, msg.Id, msg.Acknowledgment);&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;                }&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;            }&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px;"&gt;&lt;span style="font-size:85%;"&gt;        }&lt;/span&gt;&lt;/p&gt; &lt;/div&gt;  &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-2843859151760189277?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/2843859151760189277/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=2843859151760189277' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/2843859151760189277'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/2843859151760189277'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2007/12/msmq-primer.html' title='MSMQ Primer'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_VjiZepP-keA/R1bND5ZMNWI/AAAAAAAAADA/-beKBvsnmLY/s72-c/queue_names.gif' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-664916822249307055</id><published>2007-12-01T23:29:00.001-05:00</published><updated>2007-12-01T23:34:53.264-05:00</updated><title type='text'>DBCC Commands</title><content type='html'>Some useful DBCC commands are:&lt;br /&gt;&lt;br /&gt;DBCC CHECKIDENT ('authors',RESEED,0)&lt;br /&gt;&lt;br /&gt;DBCC DROPCLEANBUFFERS --- Removes all clean buffers from the buffer pool&lt;br /&gt;DBCC FREEPROCCACHE -- this clears the proc cache on all db's on the server.&lt;br /&gt;DBCC FLUSHPROCINDB ---- clears the cache for a paricular DB&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;You can create PROXY users in SQL 2005 using 2 methods&lt;br /&gt;1 CREATE USER greg WITHOUT LOGIN&lt;br /&gt;&lt;br /&gt;2.  create certificate al_cert with subject='certificate for al'&lt;br /&gt;     create user al FOR CERTIFICATE al_cert.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-664916822249307055?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/664916822249307055/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=664916822249307055' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/664916822249307055'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/664916822249307055'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2007/12/dbcc-commands.html' title='DBCC Commands'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-3214943672755617912</id><published>2007-11-26T09:30:00.001-05:00</published><updated>2007-11-26T10:10:42.357-05:00</updated><title type='text'>Conditional TSQL sorting using CASE statement</title><content type='html'>We can do conditional sorting in 2 ways.&lt;br /&gt;1. using dynamic SQL&lt;br /&gt;2. using CASE statements.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;1. using Dynamic SQL&lt;/span&gt;&lt;br /&gt;DECLARE @sql nvarchar(400), @input int, @paramdef nvarchar(100)&lt;br /&gt;SELECT @input = 2, @paramdef = N'@input int'&lt;br /&gt;&lt;br /&gt;set @sql = N'if @input = 1 select * from acctlist order by email ASC; if @input = 2 select * from acctlist order by email DESC'&lt;br /&gt;&lt;br /&gt;exec sp_executesql @sql, @paramdef, @input&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;2. using CASE statements:&lt;/span&gt;&lt;br /&gt;select * from authors&lt;br /&gt;order by&lt;br /&gt;CASE WHEN @col = 'firstname' AND @order = 'ASC' THEN firstname END ASC,&lt;br /&gt;CASE WHEN @col = 'firstname' AND @order = 'DESC' THEN firstname END DESC,&lt;br /&gt;CASE WHEN @col = 'email' AND @order = 'ASC' THEN email END ASC,&lt;br /&gt;CASE WHEN @col = 'email' AND @order = 'DESC' THEN email END DESC,&lt;br /&gt;----Default sort by lastname&lt;br /&gt;CASE WHEN @order = 'ASC' THEN lastname END ASC,&lt;br /&gt;CASE WHEN @order = 'DESC' THEN lastname END DESC&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-3214943672755617912?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/3214943672755617912/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=3214943672755617912' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/3214943672755617912'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/3214943672755617912'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2007/11/conditional-tsql-sorting-using-case.html' title='Conditional TSQL sorting using CASE statement'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-8789486494238932699</id><published>2007-11-25T18:35:00.000-05:00</published><updated>2007-11-25T18:53:31.593-05:00</updated><title type='text'>Creating ServerTraces using SQL Profiler for background profiling</title><content type='html'>Follow these steps to create a server trace for either SQL 2000 or SQL 2005.&lt;br /&gt;Server Traces are used for running traces in the background so that SQL server does not have to pump profiling results back to the SQL 2005 Profiler, it can log to a file instead.&lt;br /&gt;&lt;br /&gt;Note you can create server trace script files for either the SQL 2000 or SQL 2005 using the SQL 2005 Profiler tool:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;First use Profiler to define the events, columns, and filters needed. Some Events are : SQL:BatchCompleted and RPC:Completed, SP:StmtCompleted. Important columns are : Duration, CPU, Reads and Writes. Some advanced events are SP:Recompile and Scan:Started to check for table and index scans&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Click the Run button. Immediately stop the trace&lt;/li&gt;&lt;li&gt;Click the File menu, expand the Export option, and then expand the Script Trace Definition option. Choose For SQL Server 2005 (or SQL 2000 if creating script for older SQL Server) and select a filename to save the script.&lt;/li&gt;&lt;li&gt;Once the script has been saved, open it for editing in SQL Server Management Studio.&lt;br /&gt;The following line of the script must be edited, and a valid path must be specified, including a filename:&lt;br /&gt;exec @rc = sp_trace_create @TraceID output, 0, N'&lt;span style="font-weight: bold;"&gt;InsertFileNameHere&lt;/span&gt;',&lt;br /&gt;@maxfilesize, NULL. The @maxfilesize is 5MB by default&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Run the script. The generated script will also select back a @traceID&lt;/li&gt;&lt;li&gt;Once you are done use the @traceID to stop and close the trace:&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;EXEC sp_trace_setstatus @traceid=99, @status=0&lt;br /&gt;EXEC sp_trace_setstatus @traceid=99, @status=2&lt;br /&gt;&lt;li&gt;The fn_trace_gettable function can be used to read the data from the trace file       :&lt;br /&gt;&lt;br /&gt;SELECT * FROM ::fn_trace_gettable('C:\Traces\myTrace.trc', 999) where 999 is the number of rollover trace files to read&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-8789486494238932699?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/8789486494238932699/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=8789486494238932699' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/8789486494238932699'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/8789486494238932699'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2007/11/creating-servertraces-using-sql.html' title='Creating ServerTraces using SQL Profiler for background profiling'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-201063828804401443</id><published>2007-11-11T18:25:00.000-05:00</published><updated>2007-11-11T18:27:40.461-05:00</updated><title type='text'>Limitationsof table variables</title><content type='html'>Refer this link&lt;a href="http://databases.aspfaq.com/database/should-i-use-a-temp-table-or-a-table-variable.html"&gt;Table Variables &lt;/a&gt;&lt;br /&gt; &lt;br /&gt;DECLARE @people TABLE &lt;br /&gt;( &lt;br /&gt;    id INT, &lt;br /&gt;    name VARCHAR(32) &lt;br /&gt;)&lt;br /&gt; &lt;br /&gt;A table variable is created in memory, and so performs slightly better than #temp tables (also because there is even less locking and logging in a table variable). A table variable might still perform I/O to tempdb (which is where the performance issues of #temp tables make themselves apparent), though the documentation is not very explicit about this. &lt;br /&gt; &lt;br /&gt;Table variables are automatically cleared when the procedure or function goes out of scope, so you don't have to remember to drop or clear the data (which can be a good thing or a bad thing; remember "release early"?). The tempdb transaction log is less impacted than with #temp tables; table variable log activity is truncated immediately, while #temp table log activity persists until the log hits a checkpoint, is manually truncated, or when the server restarts. &lt;br /&gt; &lt;br /&gt;Table variables are the only way you can use DML statements (INSERT, UPDATE, DELETE) on temporary data within a user-defined function. You can create a table variable within a UDF, and modify the data using one of the above statements. For example, you could do this: &lt;br /&gt; &lt;br /&gt;CREATE FUNCTION dbo.example1 &lt;br /&gt;( &lt;br /&gt;) &lt;br /&gt;RETURNS INT &lt;br /&gt;AS &lt;br /&gt;BEGIN &lt;br /&gt;    DECLARE @t1 TABLE (i INT) &lt;br /&gt;    INSERT @t1 VALUES(1) &lt;br /&gt;    INSERT @t1 VALUES(2) &lt;br /&gt;    UPDATE @t1 SET i = i + 5 &lt;br /&gt;    DELETE @t1 WHERE i &lt; 7 &lt;br /&gt; &lt;br /&gt;    DECLARE @max INT &lt;br /&gt;    SELECT @max = MAX(i) FROM @t1 &lt;br /&gt;    RETURN @max &lt;br /&gt;END &lt;br /&gt;GO&lt;br /&gt; &lt;br /&gt;However, try that with a #temp table: &lt;br /&gt; &lt;br /&gt;CREATE FUNCTION dbo.example2 &lt;br /&gt;( &lt;br /&gt;) &lt;br /&gt;RETURNS INT &lt;br /&gt;AS &lt;br /&gt;BEGIN &lt;br /&gt;    CREATE TABLE #t1 (i INT) &lt;br /&gt;    INSERT #t1 VALUES(1) &lt;br /&gt;    INSERT #t1 VALUES(2) &lt;br /&gt;    UPDATE #t1 SET i = i + 5 &lt;br /&gt;    DELETE #t1 WHERE i &lt; 7 &lt;br /&gt; &lt;br /&gt;    DECLARE @max INT &lt;br /&gt;    SELECT @max = MAX(i) FROM #t1 &lt;br /&gt;    RETURN @max &lt;br /&gt;END &lt;br /&gt;GO&lt;br /&gt; &lt;br /&gt;Results: &lt;br /&gt; &lt;br /&gt;Server: Msg 2772, Level 16, State 1, Procedure example2, Line 7 &lt;br /&gt;Cannot access temporary tables from within a function.&lt;br /&gt; &lt;br /&gt;Or try accessing a permanent table: &lt;br /&gt; &lt;br /&gt;CREATE TABLE table1 &lt;br /&gt;( &lt;br /&gt;    id INT IDENTITY, &lt;br /&gt;    name VARCHAR(32) &lt;br /&gt;) &lt;br /&gt;GO &lt;br /&gt; &lt;br /&gt;CREATE FUNCTION dbo.example3 &lt;br /&gt;( &lt;br /&gt;) &lt;br /&gt;RETURNS INT &lt;br /&gt;AS &lt;br /&gt;BEGIN &lt;br /&gt;    INSERT table1(name) VALUES('aaron') &lt;br /&gt;    RETURN SCOPE_IDENTITY() &lt;br /&gt;END &lt;br /&gt;GO&lt;br /&gt; &lt;br /&gt;Results: &lt;br /&gt; &lt;br /&gt;Server: Msg 443, Level 16, State 2, Procedure example3, Line 8 &lt;br /&gt;Invalid use of 'INSERT' within a function.&lt;br /&gt; &lt;br /&gt;Table variables can lead to fewer stored procedure recompilations than temporary tables (see KB #243586 and KB #305977), and — since they cannot be rolled back — do not bother with the transaction log. &lt;br /&gt; &lt;br /&gt;So, why not use table variables all the time? Well, when something sounds too good to be true, it probably is. Let's visit some of the limitations of table variables (part of this list was derived from KB #305977): &lt;br /&gt;&lt;br /&gt;    * Table variables are only allowed in SQL Server 2000+, with compatibility level set to 80 or higher. &lt;br /&gt;       &lt;br /&gt;    * You cannot use a table variable in either of the following situations: &lt;br /&gt;       &lt;br /&gt;      INSERT @table EXEC sp_someProcedure &lt;br /&gt;       &lt;br /&gt;      SELECT * INTO @table FROM someTable&lt;br /&gt;       &lt;br /&gt;    * You cannot truncate a table variable. &lt;br /&gt;       &lt;br /&gt;    * Table variables cannot be altered after they have been declared. &lt;br /&gt;       &lt;br /&gt;    * You cannot explicitly add an index to a table variable, however you can create a system index through a PRIMARY KEY CONSTRAINT, and you can add as many indexes via UNIQUE CONSTRAINTs as you like. What the optimizer does with them is another story. &lt;G&gt; One thing to note is that you cannot explicitly name your constraints, e.g.: &lt;br /&gt;       &lt;br /&gt;      DECLARE @myTable TABLE &lt;br /&gt;      ( &lt;br /&gt;          CPK1 int, &lt;br /&gt;          CPK2 int, &lt;br /&gt;          CONSTRAINT myPK PRIMARY KEY (CPK1, CPK2) &lt;br /&gt;      ) &lt;br /&gt;       &lt;br /&gt;      -- yields: &lt;br /&gt;      Server: Msg 156, Level 15, State 1, Line 6 &lt;br /&gt;      Incorrect syntax near the keyword 'CONSTRAINT'. &lt;br /&gt;       &lt;br /&gt;      -- yet the following works: &lt;br /&gt;      DECLARE @myTable TABLE &lt;br /&gt;      ( &lt;br /&gt;          CPK1 int, &lt;br /&gt;          CPK2 int, &lt;br /&gt;          PRIMARY KEY (CPK1, CPK2) &lt;br /&gt;      )&lt;br /&gt;       &lt;br /&gt;    * You cannot use a user-defined function (UDF) in a CHECK CONSTRAINT, computed column, or DEFAULT CONSTRAINT. &lt;br /&gt;       &lt;br /&gt;    * You cannot use a user-defined type (UDT) in a column definition. &lt;br /&gt;       &lt;br /&gt;    * Unlike a #temp table, you cannot drop a table variable when it is no longer necessary—you just need to let it go out of scope. &lt;br /&gt;       &lt;br /&gt;    * You cannot generate a table variable's column list dynamically, e.g. you can't do this: &lt;br /&gt;       &lt;br /&gt;      SELECT * INTO @tableVariable &lt;br /&gt;       &lt;br /&gt;      -- yields: &lt;br /&gt;       &lt;br /&gt;      Server: Msg 170, Level 15, State 1, Line 1 &lt;br /&gt;      Line 1: Incorrect syntax near '@tableVariable'.&lt;br /&gt;       &lt;br /&gt;      You also can't build the table variable inside dynamic SQL, and expect to use it outside that scope, e.g.: &lt;br /&gt;       &lt;br /&gt;      DECLARE @colList VARCHAR(8000), @sql VARCHAR(8000) &lt;br /&gt;      SET @colList = 'a INT,b INT,c INT' &lt;br /&gt;      SET @sql = 'DECLARE @foo TABLE('+@colList+')' &lt;br /&gt;      EXEC(@sql) &lt;br /&gt;      INSERT @foo SELECT 1,2,3 &lt;br /&gt;       &lt;br /&gt;      -- this last line fails: &lt;br /&gt;       &lt;br /&gt;      Server: Msg 137, Level 15, State 2, Line 5 &lt;br /&gt;      Must declare the variable '@foo'.&lt;br /&gt;       &lt;br /&gt;      This is because the rest of the script knows nothing about the temporary objects created within the dynamic SQL. Like other local variables, table variables declared inside of a dynamic SQL block (EXEC or sp_executeSQL) cannot be referenced from outside, and vice-versa. So you would have to write the whole set of statements to create and operate on the table variable, and perform it with a single call to EXEC or sp_executeSQL. &lt;br /&gt;       &lt;br /&gt;    * The system will not generate automatic statistics on table variables. Likewise, you cannot manually create statistics (statistics are used to help the optimizer pick the best possible query plan). &lt;br /&gt;       &lt;br /&gt;    * An INSERT into a table variable will not take advantage of parallelism. &lt;br /&gt;       &lt;br /&gt;    * A table variable will always have a cardinality of 1, because the table doesn't exist at compile time. &lt;br /&gt;       &lt;br /&gt;    * Table variables must be referenced by an alias, except in the FROM clause. Consider the following two scripts: &lt;br /&gt;       &lt;br /&gt;      CREATE TABLE #foo(id INT) &lt;br /&gt;      DECLARE @foo TABLE(id INT) &lt;br /&gt;      INSERT #foo VALUES(1) &lt;br /&gt;      INSERT #foo VALUES(2) &lt;br /&gt;      INSERT #foo VALUES(3) &lt;br /&gt;      INSERT @foo SELECT * FROM #foo &lt;br /&gt;       &lt;br /&gt;      SELECT id &lt;br /&gt;          FROM @foo &lt;br /&gt;          INNER JOIN #foo &lt;br /&gt;          ON @foo.id = #foo.id &lt;br /&gt;       &lt;br /&gt;      DROP TABLE #foo&lt;br /&gt;       &lt;br /&gt;      The above fails with the following error: &lt;br /&gt;       &lt;br /&gt;      Server: Msg 137, Level 15, State 2, Line 11 &lt;br /&gt;      Must declare the variable '@foo'.&lt;br /&gt;       &lt;br /&gt;      This query, on the other hand, works fine: &lt;br /&gt;       &lt;br /&gt;      SELECT id &lt;br /&gt;          FROM @foo f &lt;br /&gt;          INNER JOIN #foo &lt;br /&gt;          ON f.id = #foo.id&lt;br /&gt;       &lt;br /&gt;       &lt;br /&gt;    * Table variables are not visible to the calling procedure in the case of nested procs. The following is legal with #temp tables: &lt;br /&gt;       &lt;br /&gt;      CREATE PROCEDURE faq_outer &lt;br /&gt;      AS &lt;br /&gt;      BEGIN &lt;br /&gt;          CREATE TABLE #outer &lt;br /&gt;          ( &lt;br /&gt;              letter CHAR(1) &lt;br /&gt;          ) &lt;br /&gt;       &lt;br /&gt;          EXEC faq_inner &lt;br /&gt;       &lt;br /&gt;          SELECT letter FROM #outer &lt;br /&gt;       &lt;br /&gt;          DROP TABLE #outer &lt;br /&gt;      END &lt;br /&gt;      GO &lt;br /&gt;       &lt;br /&gt;      CREATE PROCEDURE faq_inner &lt;br /&gt;      AS &lt;br /&gt;      BEGIN &lt;br /&gt;          INSERT #outer VALUES('a') &lt;br /&gt;      END &lt;br /&gt;      GO &lt;br /&gt;       &lt;br /&gt;       &lt;br /&gt;      EXEC faq_outer&lt;br /&gt;       &lt;br /&gt;      Results: &lt;br /&gt;       &lt;br /&gt;      letter  &lt;br /&gt;      ------  &lt;br /&gt;      a &lt;br /&gt;       &lt;br /&gt;      (1 row(s) affected)&lt;br /&gt;       &lt;br /&gt;      However, you cannot do this with table variables. The parser will find the error before you can even create it: &lt;br /&gt;       &lt;br /&gt;      CREATE PROCEDURE faq_outer &lt;br /&gt;      AS &lt;br /&gt;      BEGIN &lt;br /&gt;          DECLARE @outer TABLE &lt;br /&gt;          ( &lt;br /&gt;              letter CHAR(1) &lt;br /&gt;          ) &lt;br /&gt;       &lt;br /&gt;          EXEC faq_inner &lt;br /&gt;       &lt;br /&gt;          SELECT letter FROM @outer &lt;br /&gt;      END &lt;br /&gt;      GO &lt;br /&gt;       &lt;br /&gt;      CREATE PROCEDURE faq_inner &lt;br /&gt;      AS &lt;br /&gt;      BEGIN &lt;br /&gt;          INSERT @outer VALUES('a') &lt;br /&gt;      END &lt;br /&gt;      GO&lt;br /&gt;       &lt;br /&gt;      Results: &lt;br /&gt;       &lt;br /&gt;      Server: Msg 137, Level 15, State 2, Procedure faq_inner, Line 4 &lt;br /&gt;      Must declare the variable '@outer'.&lt;br /&gt;       &lt;br /&gt;      For more information about sharing data between stored procedures, please see &lt;a href="http://www.sommarskog.se/share_data.html"&gt;this &lt;/a&gt;article by Erland Sommarskog.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-201063828804401443?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/201063828804401443/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=201063828804401443' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/201063828804401443'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/201063828804401443'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2007/11/limitationsof-table-variables.html' title='Limitationsof table variables'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-7593194944515956298</id><published>2007-10-31T12:15:00.000-04:00</published><updated>2007-10-31T12:17:05.769-04:00</updated><title type='text'>TSQL: Parsing delimited string into table</title><content type='html'>CREATE    FUNCTION dbo.udf_ItemParse (&lt;br /&gt;   @Input VARCHAR(8000), @Delimeter char(1)='|'&lt;br /&gt;)&lt;br /&gt;RETURNS @ItemList TABLE (&lt;br /&gt;   Item VARCHAR(50) ,&lt;br /&gt;   Pos int&lt;br /&gt;)&lt;br /&gt;AS&lt;br /&gt;BEGIN&lt;br /&gt;&lt;br /&gt; DECLARE @Item varchar(50)&lt;br /&gt; DECLARE @StartPos int, @Length int&lt;br /&gt; DECLARE @Pos int&lt;br /&gt; SET @Pos = 0&lt;br /&gt; WHILE LEN(@Input) &amp;gt; 0&lt;br /&gt;   BEGIN&lt;br /&gt;  SET @StartPos = CHARINDEX(@Delimeter, @Input)&lt;br /&gt;  IF @StartPos &amp;lt; 0 SET @StartPos = 0&lt;br /&gt;  SET @Length = LEN(@Input) - @StartPos - 1&lt;br /&gt;  IF @Length &amp;lt; 0 SET @Length = 0&lt;br /&gt;  IF @StartPos &amp;gt; 0&lt;br /&gt;    BEGIN&lt;br /&gt;   SET @Pos = @Pos + 1&lt;br /&gt;   SET @Item = SUBSTRING(@Input, 1, @StartPos - 1)&lt;br /&gt;   SET @Input = SUBSTRING(@Input, @StartPos + 1, LEN(@Input) - @StartPos)&lt;br /&gt;    END&lt;br /&gt;  ELSE&lt;br /&gt;    BEGIN&lt;br /&gt;   SET @Pos = @Pos+1&lt;br /&gt;   SET @Item = @Input&lt;br /&gt;   SET @Input = ''&lt;br /&gt;    END&lt;br /&gt;  INSERT @ItemList (Item, Pos) VALUES(@Item, @Pos)&lt;br /&gt; END&lt;br /&gt; RETURN&lt;br /&gt;END&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-7593194944515956298?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/7593194944515956298/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=7593194944515956298' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/7593194944515956298'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/7593194944515956298'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2007/10/tsql-parsing-delimited-string-into.html' title='TSQL: Parsing delimited string into table'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-3042619935560648834</id><published>2007-10-26T13:17:00.000-04:00</published><updated>2007-10-26T13:23:55.814-04:00</updated><title type='text'>SoapExtension for Logging Soap Exceptions</title><content type='html'>using System;&lt;br /&gt;using System.Web;&lt;br /&gt;using System.Web.Services;&lt;br /&gt;using System.Web.Services.Protocols;&lt;br /&gt;using System.IO;&lt;br /&gt;using System.Xml;&lt;br /&gt;using MIT.BizServices.MCUtil.Misc;&lt;br /&gt;&lt;br /&gt;namespace MIT.Common.ExceptionHandlingSoapExtension&lt;br /&gt;{&lt;br /&gt; // &lt;summary&gt;&lt;br /&gt; // SOAP extension to transfer full exception information from&lt;br /&gt; // server to client in the event of an exception being thrown&lt;br /&gt; // from a webmethod&lt;br /&gt; // &lt;/summary&gt;&lt;br /&gt; // &lt;remarks&gt;&lt;br /&gt; // In the event of an exception being thrown during the execution&lt;br /&gt; // of a webmethod on the server, this class steps in and writes detailed&lt;br /&gt; // exception information to the output stream.&lt;br /&gt; //&lt;br /&gt; // Client side, if an exception is detected on the response from a&lt;br /&gt; // webmethod call, this class retrieves the detailed exception&lt;br /&gt; // information from the input stream and throws an exception&lt;br /&gt; // containing the detailed information&lt;br /&gt; // &lt;/remarks&gt;&lt;br /&gt; public class ExceptionHandlingSoapExtension : SoapExtension&lt;br /&gt; {    &lt;br /&gt;&lt;br /&gt;     region "Initialisation methods - not used because this class has no state to maintain"&lt;br /&gt;     public override object GetInitializer(System.Type serviceType) {&lt;br /&gt;         return null;&lt;br /&gt;     }    &lt;br /&gt;&lt;br /&gt;     public override object GetInitializer(System.Web.Services.Protocols.LogicalMethodInfo methodInfo, System.Web.Services.Protocols.SoapExtensionAttribute attribute) {&lt;br /&gt;         return null;&lt;br /&gt;     }    &lt;br /&gt;&lt;br /&gt;     public override void Initialize(object initializer)&lt;br /&gt;     {&lt;br /&gt;     }    &lt;br /&gt;     endregion&lt;br /&gt;&lt;br /&gt;     region "Stream chaining code"&lt;br /&gt;     private Stream oldStream;&lt;br /&gt;     private Stream newStream;&lt;br /&gt;&lt;br /&gt;     public override Stream ChainStream(Stream stream) {&lt;br /&gt;         oldStream = stream;&lt;br /&gt;         newStream = new MemoryStream();&lt;br /&gt;         return newStream;&lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt;     // &lt;summary&gt;&lt;br /&gt;     // Copies the contents of one stream to another&lt;br /&gt;     // &lt;/summary&gt;&lt;br /&gt;private void StreamCopy(Stream source, Stream dest) {&lt;br /&gt;         StreamReader Reader = new StreamReader(source);&lt;br /&gt;         StreamWriter Writer = new StreamWriter(dest);&lt;br /&gt;         Writer.WriteLine(Reader.ReadToEnd());&lt;br /&gt;         Writer.Flush();&lt;br /&gt;     }&lt;br /&gt;     endregion&lt;br /&gt;&lt;br /&gt;     public override void ProcessMessage(System.Web.Services.Protocols.SoapMessage message)&lt;br /&gt;     {&lt;br /&gt;         switch (message.Stage)&lt;br /&gt;         {&lt;br /&gt;             case SoapMessageStage.BeforeSerialize:&lt;br /&gt;                 return;&lt;br /&gt;&lt;br /&gt;             case SoapMessageStage.AfterSerialize:&lt;br /&gt;                 //If exception present in message, write details&lt;br /&gt;                 //to the new stream&lt;br /&gt;                 if (message.Exception != null)&lt;br /&gt;                 {&lt;br /&gt;                     InsertExceptionDetails(message.Exception);&lt;br /&gt;                 }&lt;br /&gt;&lt;br /&gt;                 //Copy new stream to old stream&lt;br /&gt;                 newStream.Position = 0;&lt;br /&gt;                 StreamCopy(newStream, oldStream);&lt;br /&gt;                 return;&lt;br /&gt;&lt;br /&gt;             case SoapMessageStage.BeforeDeserialize:&lt;br /&gt;                 //Copy old stream to new stream&lt;br /&gt;                 StreamCopy(oldStream, newStream);&lt;br /&gt;                 newStream.Position = 0;&lt;br /&gt;                 return;&lt;br /&gt;&lt;br /&gt;             case SoapMessageStage.AfterDeserialize:&lt;br /&gt;                 //If exception present in message,&lt;br /&gt;                 //get details from stream and throw to caller&lt;br /&gt;                 if (message.Exception != null)&lt;br /&gt;                 {&lt;br /&gt;                     CheckExceptionDetails();                    &lt;br /&gt;                 }&lt;br /&gt;                 return;&lt;br /&gt;&lt;br /&gt;             default:&lt;br /&gt;                 throw new ArgumentException("Invalid message stage");                &lt;br /&gt;&lt;br /&gt;         }&lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt;     // &lt;summary&gt;&lt;br /&gt;     // Insert details of the specified exception into the output stream&lt;/summary&gt;&lt;br /&gt;     // &amp;lt;param name="ex"&amp;gt;Exception to write details for    &lt;br /&gt;     private void InsertExceptionDetails(Exception ex) {&lt;br /&gt;         //Read output stream into XML document&lt;br /&gt;         newStream.Position = 0;&lt;br /&gt;         XmlTextReader Reader = new XmlTextReader(newStream);&lt;br /&gt;         XmlDocument MessageDoc = new XmlDocument();&lt;br /&gt;         MessageDoc.Load(Reader);&lt;br /&gt;&lt;br /&gt;         XmlNamespaceManager NsMgr = new XmlNamespaceManager(MessageDoc.NameTable);&lt;br /&gt;         NsMgr.AddNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope/");&lt;br /&gt;&lt;br /&gt;         //Construct string describing exception&lt;br /&gt;         string ErrorInfo;&lt;br /&gt;         if (ex.InnerException != null)&lt;br /&gt;         {&lt;br /&gt;             ErrorInfo = ex.InnerException.Message;&lt;br /&gt;         }&lt;br /&gt;         else&lt;br /&gt;         {&lt;br /&gt;             ErrorInfo = ex.Message;&lt;br /&gt;         }&lt;br /&gt;         //log exception to flat file&lt;br /&gt;         Helper.LogException(string.Empty, ex);&lt;br /&gt;     &lt;br /&gt;         //Find existing soap:Fault node describing exception&lt;br /&gt;         XmlNode ExceptionNode;&lt;br /&gt;         ExceptionNode = MessageDoc.SelectSingleNode("//soap:Fault", NsMgr);&lt;br /&gt;&lt;br /&gt;         //Add extended exception detail node to Fault node&lt;br /&gt;         XmlElement ExceptionDetail;&lt;br /&gt;         ExceptionDetail = MessageDoc.CreateElement("ExtendedExceptionDetails");&lt;br /&gt;&lt;br /&gt;         ExceptionDetail.InnerText = ErrorInfo;&lt;br /&gt;&lt;br /&gt;         ExceptionNode.AppendChild(ExceptionDetail);&lt;br /&gt;&lt;br /&gt;         //Write XML document back to output stream&lt;br /&gt;         newStream = new MemoryStream();&lt;br /&gt;         MessageDoc.Save(newStream);&lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt;     // &lt;summary&gt;&lt;br /&gt;     // Reads extra exception information from stream      &lt;/summary&gt;&lt;br /&gt;     // &lt;returns&gt;Details of any exception detail found in the input stream&lt;/returns&gt;&lt;br /&gt;     private void CheckExceptionDetails()&lt;br /&gt;     {&lt;br /&gt;         //Read input stream into XML document&lt;br /&gt;         newStream.Position = 0;&lt;br /&gt;         XmlTextReader Reader = new XmlTextReader(newStream);&lt;br /&gt;         XmlDocument MessageDoc = new XmlDocument();&lt;br /&gt;         MessageDoc.Load(Reader);&lt;br /&gt;&lt;br /&gt;         XmlNamespaceManager NsMgr = new XmlNamespaceManager(MessageDoc.NameTable);&lt;br /&gt;         NsMgr.AddNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope/");&lt;br /&gt;&lt;br /&gt;         //Find extended exception detail node&lt;br /&gt;         XmlNode ExceptionDetailNode;&lt;br /&gt;         ExceptionDetailNode = MessageDoc.SelectSingleNode("//soap:Fault/ExtendedExceptionDetails", NsMgr);&lt;br /&gt;         XmlNode exception = MessageDoc.SelectSingleNode("//soap:Fault/faultstring", NsMgr);&lt;br /&gt;&lt;br /&gt;         //Return detail text if found, empty string otherwise&lt;br /&gt;         if (ExceptionDetailNode != null)&lt;br /&gt;         {&lt;br /&gt;             if (exception != null)&lt;br /&gt;             {&lt;br /&gt;                 if (exception.InnerText.Contains("WebServiceException"))&lt;br /&gt;                 {&lt;br /&gt;                     throw new WebServiceException(ExceptionDetailNode.InnerText);&lt;br /&gt;                 }&lt;br /&gt;                 else&lt;br /&gt;                 {&lt;br /&gt;                     throw new Exception(ExceptionDetailNode.InnerText);&lt;br /&gt;                 }&lt;br /&gt;             }            &lt;br /&gt;         }        &lt;br /&gt;     }&lt;br /&gt; }&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-3042619935560648834?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/3042619935560648834/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=3042619935560648834' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/3042619935560648834'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/3042619935560648834'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2007/10/soap.html' title='SoapExtension for Logging Soap Exceptions'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-5395127623907582291</id><published>2007-10-26T13:06:00.000-04:00</published><updated>2008-11-13T06:04:45.365-05:00</updated><title type='text'>Exception and Logging Application Block</title><content type='html'>&lt;span style="font-size:85%;"&gt;Add reference to the following DLL's:&lt;br /&gt;&lt;span class="pf"&gt;Microsoft.Practices.EnterpriseLibrary.Common.dll&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;Microsoft.Practices.EnterpriseLibrary.Logging&lt;br /&gt;If you intend to log information to a database, you also need to reference the &lt;span class="pf"&gt;Microsoft.Practices.EnterpriseLibrary.Data.dll&lt;/span&gt; &lt;/span&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_VjiZepP-keA/R17uSkrK2NI/AAAAAAAAADk/sAqr0V8u6JU/s1600-h/logging.jpg"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 298px; height: 196px;" src="http://1.bp.blogspot.com/_VjiZepP-keA/R17uSkrK2NI/AAAAAAAAADk/sAqr0V8u6JU/s200/logging.jpg" alt="" id="BLOGGER_PHOTO_ID_5142809827353483474" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;For adding tracing in the method call use the following:&lt;br /&gt;public DataSet GetPricingDataSet(string loanNumber)&lt;br /&gt;{&lt;br /&gt;using Tracer("Trace")&lt;br /&gt;{&lt;br /&gt;DoSomething();&lt;br /&gt;//For additional logging use:&lt;br /&gt;Logger.Write("message")&lt;br /&gt;//or use:&lt;br /&gt;Logger.Write(new LogEntry("message"))&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Add a Trace listener in the Logging Application Block via the Enterprise Library Configuration tool and then specify a Category called "Trace" which logs to this newly configured Trace Listener.&lt;br /&gt;&lt;br /&gt;For more info:&lt;br /&gt;http://www.devx.com/dotnet/Article/31463/1954?pf=true&lt;br /&gt;&lt;br /&gt;http://www.devx.com/dotnet/Article/35736?trk=DXRSS_DOTNET&lt;br /&gt;http://www.devx.com/dotnet/Article/36184?trk=DXRSS_DOTNET - Enterprise Library 3.0&lt;br /&gt;======================================================&lt;br /&gt;For Exception Handling:&lt;br /&gt;======================================================&lt;br /&gt;Add references to the following DLL's:&lt;br /&gt;ExceptionHandling.dll&lt;br /&gt;ExceptionHandling.Logging.dll&lt;br /&gt;&lt;br /&gt;     public static void LogException(string policyName, Exception ex)&lt;br /&gt;     {&lt;br /&gt;         if (string.IsNullOrEmpty(policyName))&lt;br /&gt;             policyName = ConfigurationManager.AppSettings["ExceptionPolicy"];&lt;br /&gt;         &lt;br /&gt;         ExceptionPolicy.HandleException(ex, policyName);        &lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-5395127623907582291?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/5395127623907582291/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=5395127623907582291' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/5395127623907582291'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/5395127623907582291'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2007/10/exception-and-logging-application-block.html' title='Exception and Logging Application Block'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_VjiZepP-keA/R17uSkrK2NI/AAAAAAAAADk/sAqr0V8u6JU/s72-c/logging.jpg' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-6473403311647263934</id><published>2007-10-03T17:37:00.000-04:00</published><updated>2007-10-03T17:41:36.927-04:00</updated><title type='text'>TSQL to concatenate column values into a single string</title><content type='html'>&lt;span style="font-size:85%;"&gt;DECLARE @cols AS varchar(3000)&lt;br /&gt;;&lt;br /&gt;WITH YearsCTE&lt;br /&gt;AS&lt;br /&gt;(SELECT DISTINCT YEAR(OrderDate) as [Year] FROM Sales.SalesOrderHeader)&lt;br /&gt;&lt;br /&gt;SELECT @cols = ISNULL(@cols + ',[', '[') + CAST([YEAR] AS varchar(4)) + ']'&lt;br /&gt;FROM YearsCTE&lt;br /&gt;ORDER BY [YEAR]&lt;br /&gt;&lt;br /&gt;Note the use of ISNULL. This adds a additional "," to separate records. Note the isnull helps to add the additonal "," only to records numbered 2 or greater.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-6473403311647263934?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/6473403311647263934/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=6473403311647263934' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/6473403311647263934'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/6473403311647263934'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2007/10/tsql-to-concatenate-column-values-into.html' title='TSQL to concatenate column values into a single string'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-7068988764329005159</id><published>2007-09-23T10:43:00.000-04:00</published><updated>2007-09-23T11:29:46.210-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sharepoint'/><title type='text'>Create and deploy a Sharepoint Feature</title><content type='html'>&lt;span style="font-size:85%;"&gt;Suppose you need to replace the SmallSearchInputBox on the sharepoint site with a new feature. Follow these steps:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;step1 : create a copy of existing feature e.g. controlLightUp&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;Thus copy this folder from 12\Template\Features\CustomLightUp to 12\Template\Features\NewSearchArea&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;Step2: modify feature.xml to contain the new GUID and add a reference to the element.xml (within a subdirectory or the same directory as feature.xml, whichever you prefer) which describes the feature. &lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;Specify if the feature should be HIDDEN or displayed in the Sharepoint site settings&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;Specify Title and Description if this feature is NOT Hidden&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;Step 3: then modify the elements.xml file in controls folder to have the correct settings. Scope can take one of the following values: FARM, Webapplication, Web and Site&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;Site is SiteCollection&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;Web is Site&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;Web Application is parent of Sitecollection&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;FARM is server wide enabling of the feature&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;Step4: suppose CustomLightUp feature is installed at FARM level snd it is referenced through a delagate control in the master page and its control id "SmallSearchInputBox",  and you want to create a new feature at the Site scope and for the same delegate control&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;Then there are 2 ways to achioeve this&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;1: rename the Delegate control id from "SmallSearchInput" to "newSearch" then then make the modification in elements.xml to contain this new control id. then install the feature at Site level using stsadm utility&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;2. you can keep the control id the same i.e. "SmallSearchInput" but then modify the Sequence value in elements.xml to have a value less than 100.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;(for more on this refer to my previous blog on delegate control) Then install the feature at the site level using stsadm&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;command is stsadm -o installfeature -filename NewSearchArea\feature.xml&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;stsadm -o activatefeature -filename NewSearch\feature.xml -url &lt;/span&gt;&lt;a href="http://w.c.com/"&gt;&lt;span style="font-size:85%;"&gt;http://w.c.com&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;For automatic deployment of the feature read this:&lt;/span&gt;&lt;br /&gt;&lt;a href="http://www.codeplex.com/wspbuilder"&gt;&lt;span style="font-size:85%;"&gt;http://www.codeplex.com/wspbuilder&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;Or&lt;/span&gt;&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/msdnmag/issues/07/05/OfficeSpace/"&gt;&lt;span style="font-size:85%;"&gt;http://msdn.microsoft.com/msdnmag/issues/07/05/OfficeSpace/&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;and&lt;/span&gt;&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/msdnmag/issues/07/08/OfficeSpace/"&gt;&lt;span style="font-size:85%;"&gt;http://msdn.microsoft.com/msdnmag/issues/07/08/OfficeSpace/&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;if you want to list all existing features then you need to extend the stsadm utility:&lt;/span&gt;&lt;br /&gt;&lt;a href="http://sharepointsolutions.blogspot.com/2006/09/extending-stsadmexe-with-custom.html"&gt;&lt;span style="font-size:85%;"&gt;http://sharepointsolutions.blogspot.com/2006/09/extending-stsadmexe-with-custom.html&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;and&lt;/span&gt;&lt;br /&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/bb417382.aspx"&gt;&lt;span style="font-size:85%;"&gt;http://msdn2.microsoft.com/en-us/library/bb417382.aspx&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;and&lt;/span&gt;&lt;br /&gt;&lt;a href="http://www.andrewconnell.com/blog/articles/MossStsadmWcmCommands.aspx"&gt;&lt;span style="font-size:85%;"&gt;http://www.andrewconnell.com/blog/articles/MossStsadmWcmCommands.aspx&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;and&lt;/span&gt;&lt;br /&gt;&lt;a href="http://stsadm.blogspot.com/2007/08/enumerate-features.html"&gt;&lt;span style="font-size:85%;"&gt;http://stsadm.blogspot.com/2007/08/enumerate-features.html&lt;/span&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-7068988764329005159?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/7068988764329005159/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=7068988764329005159' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/7068988764329005159'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/7068988764329005159'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2007/09/create-and-deploy-sharepoint-feature.html' title='Create and deploy a Sharepoint Feature'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-6861734213903716146</id><published>2007-09-21T12:58:00.000-04:00</published><updated>2007-09-23T11:32:07.725-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Continuous Integration'/><title type='text'>Automating Dev, QA, Staging, and Production Web.Config Settings with VS 2005</title><content type='html'>&lt;span style="font-family:arial;font-size:85%;"&gt; &lt;p&gt;One of the questions I get asked fairly regularly is: "how can I can easily change different configuration settings in my web.config file based on whether my application is in a dev, qa, staging or production mode?"  The most common scenario for this is one where an application uses different database connection-strings for testing and production purposes.&lt;/p&gt; &lt;p&gt;It turns out you can easily automate this configuration process within the Visual Studio build environment (and do so in a way that works both within the IDE, as well as with command-line/automated builds).  Below are the high-level steps you take to do this.  They work with both VS 2005 and VS 2008.&lt;/p&gt; &lt;ol&gt;&lt;li&gt;Use ASP.NET Web Application Projects (which have MSBuild based project files)&lt;/li&gt;&lt;li&gt;Open the VS Configuration Manager and create new "Dev", "QA", "Staging" build configurations for your project and solution&lt;/li&gt;&lt;li&gt;Add new "web.config.dev", "web.config.qa", and "web.config.staging" files in your project and customize them to contain the app's mode specific configuration settings &lt;/li&gt;&lt;li&gt;Add a new "pre-build event" command to your project file that can automatically copy over the web.config file in your project with the appropriate mode specific version each time you build the project (for example: if your solution was in the "Dev" configuration, it would copy the web.config.dev settings to the main web.config file).&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;Once you follow these steps, you can then just pick the mode your solution is in using the configuration drop-down in the VS standard toolbar:&lt;/p&gt; &lt;p&gt;&lt;img src="http://www.hanselman.com/blog/content/binary/WindowsLiveWriter/43756dc3d413_142D5/image_2.png" /&gt; &lt;/p&gt; &lt;p&gt;The next time you build/run after changing the configuration mode, VS will automatically modify your application's web.config file to pick up and use the web.config settings specific to that build configuration (so if you select QA it will use the QA settings, if you select Deploy it will use the Deploy settings).&lt;/p&gt; &lt;p&gt;The benefit with this approach is that it works well in a source control environment (everyone can sync and build locally without having to make any manual changes on their local machines).  It also works on a build server - including with scenarios where you are doing automated command-line solution builds.&lt;/p&gt; &lt;p&gt;To learn more about the exact steps to set this up, please read the &lt;a href="http://www.hanselman.com/blog/ManagingMultipleConfigurationFileEnvironmentsWithPreBuildEvents.aspx" target="_blank"&gt;Managing Multiple Configuration File Environments with Pre-Build Events&lt;/a&gt; post that Scott Hanselman published earlier tonight.  Also check out ScottGu's &lt;a href="http://weblogs.asp.net/scottgu/pages/ASP.NET-2.0-Tips_2C00_-Tricks_2C00_-Recipes-and-Gotchas.aspx" target="_blank"&gt;ASP.NET Tips, Tricks, and Gotchas page&lt;/a&gt; for other ASP.NET Tips/Tricks recommendations.&lt;/p&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-6861734213903716146?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/6861734213903716146/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=6861734213903716146' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/6861734213903716146'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/6861734213903716146'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2007/09/automating-dev-qa-staging-and.html' title='Automating Dev, QA, Staging, and Production Web.Config Settings with VS 2005'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-8032773166215618763</id><published>2007-09-18T17:29:00.000-04:00</published><updated>2007-09-23T11:32:32.746-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='aspnet20'/><title type='text'>multi column sorting of a typed collection</title><content type='html'>Use the following One line code for multi-column or single column sorting of a typed collection:&lt;br /&gt;&lt;br /&gt;List&lt;liability&gt;&amp;lt;Liability&amp;gt; liabList = new List&amp;lt;Liability&amp;gt;&lt;liability&gt;();&lt;br /&gt;&lt;br /&gt;              liabList.Sort(delegate(Liability l1, Liability l2)&lt;br /&gt;              { int r = l1.Type.CompareTo(l2.Type);&lt;br /&gt;                  if (r == 0 &amp;amp;&amp;amp; l1.HolderName != null)&lt;br /&gt;                      r = l1.HolderName.CompareTo(l2.HolderName);&lt;br /&gt;                  if (r == 0)&lt;br /&gt;                       r = l1.Amount.CompareTo(l2.Amount);&lt;br /&gt;                  return r;&lt;br /&gt;              }   );&lt;/liability&gt;&lt;/liability&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-8032773166215618763?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/8032773166215618763/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=8032773166215618763' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/8032773166215618763'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/8032773166215618763'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2007/09/multi-column-sorting-of-typed.html' title='multi column sorting of a typed collection'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-1040105138930902088</id><published>2007-06-27T10:28:00.000-04:00</published><updated>2007-09-23T11:32:07.726-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Continuous Integration'/><title type='text'>Nant Intellisense with Nant Contrib tasks and VS2005 nant Addin</title><content type='html'>Nant Intellisense with Nant Contrib tasks and VS2005 nant Addin.&lt;br /&gt;&lt;br /&gt;First task is to generate the XSD (schema) file that needs to be added inorder to enable intellisense.&lt;br /&gt;use the following Nant .build script to generate the nant.xsd file:&lt;br /&gt;&lt;br /&gt;   &amp;lt;project name="nant" default="go"&amp;gt;&lt;br /&gt;     &amp;lt;property name="NAntContrib" value="c:\rohit\nantcontrib-0.85\bin" /&amp;gt;&lt;br /&gt;     &amp;lt;target name="go"&amp;gt;&lt;br /&gt;       &amp;lt;loadtasks assembly="${NAntContrib}\NAnt.Contrib.Tasks.dll" /&amp;gt;&lt;br /&gt;       &amp;lt;nantschema output="nant.xsd" target-ns="http://nant.sf.net/nightly/2006-03-08-0.85/nant.xsd"/&amp;gt;&lt;br /&gt;     &amp;lt;/target&amp;gt;&lt;br /&gt;   &amp;lt;/project&amp;gt;&lt;br /&gt;  &lt;project name="nant" default="go"&gt;&lt;property name="NAntContrib" value="c:\devtools\nantcontrib-0.85\bin"&gt;&lt;target name="go"&gt;&lt;loadtasks assembly="${NAntContrib}\NAnt.Contrib.Tasks.dll"&gt;&lt;nantschema output="nant.xsd" ns="http://nant.sf.net/nightly/2006-03-08-0.85/nant.xsd"&gt;&lt;/nantschema&gt;&lt;/loadtasks&gt;&lt;br /&gt;Build this script using nant:&lt;br /&gt;nant /f:nantxsd.build&lt;br /&gt;This will create the nant.xsd file.&lt;br /&gt;&lt;br /&gt;Copy this file nant.xsd to 'C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\Packages\schemas\xml' on your system, or if you are using VS2005 then copy to "C:\Program Files\Microsoft Visual Studio 8\Xml\Schemas".&lt;br /&gt;&lt;br /&gt;In your NAnt build file (I make my with the extension .build) include this &lt;strong&gt;xmlns &lt;/strong&gt;attribute:&lt;br /&gt;&lt;project xmlns="http://nant.sf.net/nightly/2006-03-08-0.85/nant.xsd" name="test" default="build" basedir="."&gt;&amp;lt;project xmlns="http://nant.sf.net/nightly/2006-03-08-0.85/nant.xsd" name="test" default="build"&amp;gt;&lt;br /&gt;&lt;br /&gt;Now you will get intellisense for all nant tasks as well nant contrib tasks.&lt;br /&gt;==============================================================&lt;br /&gt;To add the Nant Addin for VS2005.&lt;br /&gt;Download Nant addin from:&lt;br /&gt;http://sourceforge.net/projects/nantaddin&lt;br /&gt;&lt;br /&gt;Create a directory for Visual Studio Addins        ex : "%Program Files%/Microsoft Visual Studio 8/Addins"        Copy the NAntAddin directory along with the "NAntAddin.AddIn" file into it.&lt;br /&gt;&lt;br /&gt;open VS2005. click Tools\Options.&lt;br /&gt;Click on Envrironment\"Add-in/Macros Security"&lt;br /&gt;Then click "Add" to add the "%Program Files%/Microsoft Visual Studio 8/Addins" directory.&lt;br /&gt;&lt;br /&gt;Restart VS 2005.&lt;br /&gt;Then click Tools\Add-in Manager.&lt;br /&gt;Then check the checkbox against "NantAddin".&lt;br /&gt;&lt;br /&gt;Now you will be able to run nant scripts or part of it directly from within VS2005.&lt;br /&gt;&lt;img src="file:///C:/DOCUME%7E1/rogupta/LOCALS%7E1/Temp/moz-screenshot.jpg" alt="" /&gt;&lt;/project&gt;&lt;/target&gt;&lt;/property&gt;&lt;/project&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-1040105138930902088?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/1040105138930902088/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=1040105138930902088' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/1040105138930902088'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/1040105138930902088'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2007/06/nant-intellisense-with-nant-contrib.html' title='Nant Intellisense with Nant Contrib tasks and VS2005 nant Addin'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-7808994258280116181</id><published>2007-06-27T09:54:00.000-04:00</published><updated>2007-06-27T10:18:37.872-04:00</updated><title type='text'>Turning an ascx user control into a redistributable custom control</title><content type='html'>This is possible using the new binary compilation feature of ASP.NET 2.0 and also the availability of the ClassName property on the user control.&lt;br /&gt;The ClassName property allows to specify the Namespace that is needed when consuming the usercontrol from another application.&lt;br /&gt;&lt;br /&gt;We can publish multiple controls within a single assembly but we have to insure that the Web project contains just UserControls only (ascx along with the associated code behind files).&lt;br /&gt;But if you use the "use fixed naming and single page assemblies" option then a separate assembly for each user control will be generated. However the advantage of using this option is that if you were to make changes and deploy a newer version of the user control, then you need not modify the consuming application.&lt;br /&gt;&lt;br /&gt;This is since the assembly NAME will remain the same on each compilation of the user control project and thus we do not need to update the reference to the user control assembly from within the consuming application.&lt;br /&gt;&lt;br /&gt;There is one more option if you decide to use the "use fixed naming and single page assemblies".&lt;br /&gt;After separate assemblies are created using the Publish Website option (or using the aspnet_compiler.exe tool) we can then merge these assemblies into a single assembly using the aspnet_merge.exe tool. Another option to combine multiple user controls into a single assembly is by using the Web deployment projects (WDP).&lt;br /&gt;&lt;br /&gt;Read this excellent MSDN magazine article by Fritz Onion on Web Deployment projects (WDP) and for info about packaging user controls into assembly for multi application use:&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/msdnmag/issues/07/04/ExtremeASPNET/" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"&gt;http://msdn.microsoft.com&lt;wbr&gt;/msdnmag/issues/07/04/ExtremeAS&lt;wbr&gt;PNET/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;So the steps for converting a user control into a redistributable custom control are:&lt;br /&gt;1. Create the User control in a Website project in VS2005.&lt;br /&gt;The main restriction is that the User Control needs to be &lt;b&gt;self contained&lt;/b&gt;.  That is, it cannot be dependent on app global things like App_Code or global.asax. If you do need to use the App_Code folder then you could use WDP or aspnet_merge.exe to combine mutiple assemblies into a single assembly.&lt;br /&gt;&lt;br /&gt;When you create the User Control (say &lt;i&gt;MyTestUC.ascx&lt;/i&gt;), VS creates it with the a @control directive that looks like this: &lt;div class="code"&gt;&lt;span style="background-color: rgb(255, 255, 153);"&gt;&lt;span style="color:blue;"&gt;&lt;&lt;/span&gt;&lt;span style="color:maroon;"&gt;%@&lt;/span&gt;&lt;span style="color:red;"&gt; Control Language&lt;/span&gt;&lt;span style="color:blue;"&gt;="C#"&lt;/span&gt;&lt;span style="color:red;"&gt; ClassName&lt;/span&gt;&lt;span style="color:blue;"&gt;="MyTestUC"&lt;/span&gt;&lt;span style="color:red;"&gt; %&lt;/span&gt;&lt;span style="color:blue;"&gt;&gt;&lt;/span&gt;&lt;/span&gt; &lt;/div&gt; &lt;p&gt;This is fine, except for one thing: we want the class to live within a namespace of our choice (instead of 'ASP', which is what's used by default).  To do this, we simply modify the ClassName attribute to include the namespace (this is a new feature in 2.0).  e.g.&lt;/p&gt; &lt;div class="code"&gt;&lt;span style="background-color: rgb(255, 255, 153);"&gt;&lt;span style="color:blue;"&gt;&lt;&lt;/span&gt;&lt;span style="color:maroon;"&gt;%@&lt;/span&gt;&lt;span style="color:red;"&gt; Control Language&lt;/span&gt;&lt;span style="color:blue;"&gt;="C#"&lt;/span&gt;&lt;span style="color:red;"&gt; ClassName&lt;/span&gt;&lt;span style="color:blue;"&gt;="&lt;b&gt;Acme.&lt;/b&gt;MyTestUC"&lt;/span&gt;&lt;span style="color:red;"&gt; %&lt;/span&gt;&lt;span style="color:blue;"&gt;&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt; &lt;/div&gt;2. Publish the website to compile the user control into a assembly.&lt;br /&gt;Note you need to "uncheck" 'Allow this precompiled site to be updatable' option within "Publish Website", or you can use aspnet_compiler along with -u switch to create a binary deployment of the user controls.&lt;br /&gt;&lt;br /&gt;3. Add reference to the generated assembly in step 2 from within the consuming web application.&lt;br /&gt;First, add a Register directive to your page.  It should look something like this: &lt;p&gt; &lt;/p&gt;&lt;span style="background-color: rgb(255, 255, 153);"&gt;&lt;span style="color:blue;"&gt;&lt;&lt;/span&gt;&lt;span style="color:maroon;"&gt;%@&lt;/span&gt;&lt;span style="color:red;"&gt; Register TagPrefix&lt;/span&gt;&lt;span style="color:blue;"&gt;="Acme"&lt;/span&gt;&lt;span style="color:red;"&gt; Namespace&lt;/span&gt;&lt;span style="color:blue;"&gt;="Acme"&lt;/span&gt;&lt;span style="color:red;"&gt; Assembly&lt;/span&gt;&lt;span style="color:blue;"&gt;="App_Web_mytestuc.ascx.cdcab7d2"&lt;/span&gt;&lt;span style="color:red;"&gt; %&lt;/span&gt;&lt;span style="color:blue;"&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;Note here that the assembly name is "App_web_mytestuc.ascx.cdcab7d2"&lt;br /&gt;This assembly was generated using the "use fixed naming and single page assemblies"&lt;br /&gt;&lt;br /&gt;the reference the user control within the page of the consuming application like this:&lt;br /&gt;&lt;span style="color:blue;"&gt;&lt;&lt;/span&gt;&lt;span style="color:maroon;"&gt;Acme:MyTestUC&lt;/span&gt;&lt;span style="color:red;"&gt; id&lt;/span&gt;&lt;span style="color:blue;"&gt;="MyUC"&lt;/span&gt;&lt;span style="color:red;"&gt; runat&lt;/span&gt;&lt;span style="color:blue;"&gt;="server"&lt;/span&gt;&lt;span style="color:red;"&gt; &lt;/span&gt;&lt;span style="color:blue;"&gt;/&gt;&lt;br /&gt;&lt;br /&gt;If you had multiple user controls within that single assembly you could then reference the second control from that assembly likewise:&lt;br /&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;&lt;&lt;/span&gt;&lt;span style="color:maroon;"&gt;Acme:MyTestUC2&lt;/span&gt;&lt;span style="color:red;"&gt; id&lt;/span&gt;&lt;span style="color:blue;"&gt;="MyUC2"&lt;/span&gt;&lt;span style="color:red;"&gt; runat&lt;/span&gt;&lt;span style="color:blue;"&gt;="server"&lt;/span&gt;&lt;span style="color:red;"&gt; &lt;/span&gt;&lt;span style="color:blue;"&gt;/&gt;&lt;br /&gt;&lt;br /&gt;That is all that is there to it.&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-7808994258280116181?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/7808994258280116181/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=7808994258280116181' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/7808994258280116181'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/7808994258280116181'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2007/06/turning-ascx-user-control-into.html' title='Turning an ascx user control into a redistributable custom control'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-5182240878373228605</id><published>2007-04-29T21:57:00.000-04:00</published><updated>2007-09-23T11:32:32.746-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='aspnet20'/><title type='text'>File Compress and File Upload</title><content type='html'>&lt;span style="font-size:85%;"&gt;/// Upload a file......&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;string strName;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;strName = System.IO.Path.GetFileName(fileUpload.PostedFile.FileName);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;try {    &lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;       fileUpload.PostedFile.SaveAs(Server.MapPath(strName));&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;       this.lblResult.Text = strName + " was uploaded successfully.";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;     }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;catch (Exception ex) &lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;   {    this.lblResult.Text = "An Error Occured While Uploading File.";}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;============================================&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;/// Compress and Upload the file ...&lt;br /&gt;string strName = Path.GetFileName(fileUpload.PostedFile.FileName);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;//Create a stream object to read the file.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;Stream myStream = fileUpload.PostedFile.InputStream;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;byte[] myBuffer = new byte[myStream.length];&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;//Read the file using the Stream object and fill the buffer.&lt;br /&gt;myStream.Read(myBuffer, 0, myBuffer.Length);&lt;br /&gt;myStream.Close();&lt;br /&gt;FileStream compresFile;&lt;br /&gt;compresFile = File.Create(Server.MapPath(Path.ChangeExtension(strName, "gz")));&lt;br /&gt;&lt;br /&gt;// Write from the buffer containing the file contents to the gzip file using the GZipStream object&lt;br /&gt;GZipStream myStreamZip = new GZipStream(compresFile, CompressionMode.Compress);&lt;br /&gt;myStreamZip.Write(myBuffer, 0, myBuffer.Length);&lt;br /&gt;myStreamZip.Close();&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-5182240878373228605?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/5182240878373228605/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=5182240878373228605' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/5182240878373228605'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/5182240878373228605'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2007/04/file-compress-and-file-upload.html' title='File Compress and File Upload'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-8475724831057637106</id><published>2007-04-24T16:48:00.000-04:00</published><updated>2007-09-23T11:32:32.746-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='aspnet20'/><title type='text'>Encryption/Decryption in .NET 2.0</title><content type='html'>&lt;p&gt;&lt;span style="font-size:85%;"&gt;using System;&lt;br /&gt;using System.IO;&lt;br /&gt;using System.Security;&lt;br /&gt;using System.Security.Cryptography;&lt;br /&gt;using System.Runtime.InteropServices;&lt;br /&gt;using System.Text;&lt;br /&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;namespace Demo&lt;br /&gt;{&lt;br /&gt;    public enum CryptoAlgo&lt;br /&gt;    {&lt;br /&gt;        DES,&lt;br /&gt;        RC2,&lt;br /&gt;        Rijndael,&lt;br /&gt;        TripleDES&lt;br /&gt;    }&lt;br /&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;    public class Crypto : IDisposable&lt;br /&gt;    {&lt;br /&gt;        //  Call this function to remove the key from memory after use for security&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;         [System.Runtime.InteropServices.DllImport("KERNEL32.DLL", EntryPoint= "RtlZeroMemory")]&lt;br /&gt;        private static extern bool ZeroMemory(IntPtr Destination, int Length);&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;         private SymmetricAlgorithm cAlgo;&lt;br /&gt;        private readonly int BufSize = 1024;&lt;br /&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;        public Crypto(CryptoAlgo algo) : this(algo, null, null)&lt;br /&gt;        {&lt;br /&gt;        }&lt;br /&gt;        public Crypto(CryptoAlgo algo, string key, string iv)&lt;br /&gt;        {&lt;br /&gt;            switch (algo)&lt;br /&gt;            {&lt;br /&gt;                case CryptoAlgo.DES:&lt;br /&gt;                    cAlgo = DES.Create();&lt;br /&gt;                    break;&lt;br /&gt;                case CryptoAlgo.RC2:&lt;br /&gt;                    cAlgo = RC2.Create();&lt;br /&gt;                    break;&lt;br /&gt;                case CryptoAlgo.Rijndael:&lt;br /&gt;                    cAlgo = Rijndael.Create();&lt;br /&gt;                    break;&lt;br /&gt;                case CryptoAlgo.TripleDES:&lt;br /&gt;                    cAlgo = TripleDES.Create();&lt;br /&gt;                    break;&lt;br /&gt;                default:&lt;br /&gt;                    throw new ArgumentOutOfRangeException("algo");&lt;br /&gt;            }&lt;br /&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;            if (key != null)&lt;br /&gt;            {&lt;br /&gt;                cAlgo.Key = Convert.FromBase64String(key);&lt;br /&gt;                cAlgo.IV = Convert.FromBase64String(iv);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;        /// &lt;summary&gt;&lt;br /&gt;        /// Gets the key for the algorithm as a Base64 string.&lt;br /&gt;        /// &lt;/summary&gt;&lt;br /&gt;        public string Key&lt;br /&gt;        {&lt;br /&gt;            get&lt;br /&gt;            {&lt;br /&gt;                return Convert.ToBase64String(cAlgo.Key);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;        /// &lt;summary&gt;&lt;br /&gt;        /// Gets the IV for the algorithm as a Base64 string.&lt;br /&gt;        /// &lt;/summary&gt;&lt;br /&gt;        public string IV&lt;br /&gt;        {&lt;br /&gt;            get { return Convert.ToBase64String(cAlgo.IV); }&lt;br /&gt;        }&lt;br /&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;        public void EncryptFile(string inPath, string outPath)&lt;br /&gt;        {&lt;br /&gt;            using (FileStream inStream = File.OpenRead(inPath))&lt;br /&gt;            using (FileStream outStream = new FileStream(outPath, FileMode.Create, FileAccess.Write))&lt;br /&gt;            {&lt;br /&gt;                EncryptStream(inStream, outStream);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;        public void DecryptFile(string inPath, string outPath)&lt;br /&gt;        {&lt;br /&gt;            using (FileStream inStream = File.OpenRead(inPath))&lt;br /&gt;            using (FileStream outStream = new FileStream(outPath, FileMode.Create, FileAccess.Write))&lt;br /&gt;            {&lt;br /&gt;                DecryptStream(inStream, outStream);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;        public byte[] EncryptBytes(byte[] buffer)&lt;br /&gt;        {&lt;br /&gt;            using (MemoryStream inStream = new MemoryStream(buffer))&lt;br /&gt;            using (MemoryStream outStream = new MemoryStream())&lt;br /&gt;            {&lt;br /&gt;                EncryptStream(inStream, outStream);&lt;br /&gt;                return outStream.ToArray();&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;        public byte[] DecryptBytes(byte[] buffer)&lt;br /&gt;        {&lt;br /&gt;            using (MemoryStream inStream = new MemoryStream(buffer))&lt;br /&gt;            using (MemoryStream outStream = new MemoryStream())&lt;br /&gt;            {&lt;br /&gt;                DecryptStream(inStream, outStream);&lt;br /&gt;                return outStream.ToArray();&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;        public void EncryptStream(Stream inStream, Stream outStream)&lt;br /&gt;        {&lt;br /&gt;using (ICryptoTransform encryptor = cAlgo.CreateEncryptor())&lt;br /&gt;using (CryptoStream cryptoStream = new CryptoStream(outStream, encryptor, CryptoStreamMode.Write))&lt;br /&gt;            {&lt;br /&gt;                // Read from in file until EOF and write to crypto stream.&lt;br /&gt;                byte[] buf = new byte[BufSize];&lt;br /&gt;                int read = 0;&lt;br /&gt;                while ((read = inStream.Read(buf, 0, buf.Length)) &gt; 0)&lt;br /&gt;                {&lt;br /&gt;                    cryptoStream.Write(buf, 0, read);&lt;br /&gt;                }&lt;br /&gt;                cryptoStream.Flush();&lt;br /&gt;                outStream.Flush();&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;        public void DecryptStream(Stream inStream, Stream outStream)&lt;br /&gt;        {&lt;br /&gt;            using (ICryptoTransform decryptor = cAlgo.CreateDecryptor())&lt;br /&gt;using (CryptoStream cryptoStream = new CryptoStream(inStream, decryptor, CryptoStreamMode.Read))&lt;br /&gt;            {&lt;br /&gt;                // Read from the cryptoStream until EOF and write decrypted bytes to outFile.&lt;br /&gt;                byte[] ba = new byte[BufSize];&lt;br /&gt;                int read = 0;&lt;br /&gt;                while ((read = cryptoStream.Read(ba, 0, ba.Length)) &gt; 0)&lt;br /&gt;                {&lt;br /&gt;                    outStream.Write(ba, 0, read);&lt;br /&gt;                }&lt;br /&gt;                outStream.Flush();&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;        public static void Test()&lt;br /&gt;        {&lt;br /&gt;            Crypto crypto = new Crypto(CryptoAlgo.DES);&lt;br /&gt;            string key = crypto.Key;&lt;br /&gt;            string iv = crypto.IV;&lt;br /&gt;            crypto.EncryptFile("c:\\mydata.txt", "c:\\encrypted.txt");&lt;br /&gt;            crypto.DecryptFile("c:\\encrypted.txt", "c:\\decrypted.txt");&lt;br /&gt;            Console.WriteLine("Decrypted.txt:");&lt;br /&gt;            Console.WriteLine(File.ReadAllText("c:\\decrypted.txt")); // Will work for text files.&lt;br /&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;            // Test decrypting with stored key.&lt;br /&gt;            crypto = new Crypto(CryptoAlgo.DES, key, iv);&lt;br /&gt;            crypto.DecryptFile("c:\\encrypted.txt", "c:\\decrypted.txt");&lt;br /&gt;            Console.WriteLine("Decrypted.txt:");&lt;br /&gt;            Console.WriteLine(File.ReadAllText("c:\\decrypted.txt")); // Will work for text files.&lt;br /&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;        }&lt;br /&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;        public void Dispose()&lt;br /&gt;        {&lt;br /&gt;            this.cAlgo.Clear();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;/span&gt; &lt;/p&gt;&lt;span style="font-size:85%;"&gt;}   &lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-8475724831057637106?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/8475724831057637106/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=8475724831057637106' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/8475724831057637106'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/8475724831057637106'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2007/04/encryptiondecryption-in-net-20.html' title='Encryption/Decryption in .NET 2.0'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-3392436018210496066</id><published>2007-04-20T15:53:00.000-04:00</published><updated>2007-09-23T11:32:32.747-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='aspnet20'/><title type='text'>Convert string to Stream</title><content type='html'>&lt;pre&gt;&lt;code&gt;   private void AddAttachmentFromStream(MailMessage message, String data, String attachmentName)&lt;br /&gt;  {&lt;br /&gt;    MemoryStream stream = new MemoryStream(&lt;span style="font-weight: bold;"&gt;UTF32Encoding.Default.GetBytes&lt;/span&gt;(data));&lt;br /&gt;    stream.Position = 0;&lt;br /&gt;  // Create a new attachment, add the attachment to the supplied message.&lt;br /&gt;    Attachment att = new Attachment(stream, attachmentName);&lt;br /&gt;    message.Attachments.Add(att);&lt;br /&gt;  }&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-3392436018210496066?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/3392436018210496066/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=3392436018210496066' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/3392436018210496066'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/3392436018210496066'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2007/04/convert-string-to-stream.html' title='Convert string to Stream'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-188751464869463841</id><published>2007-04-19T16:26:00.000-04:00</published><updated>2007-09-23T11:32:32.747-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='aspnet20'/><title type='text'>PropertyComparer for SORTING a Generic List</title><content type='html'>&lt;span style=";font-family:trebuchet ms;font-size:85%;"  &gt;public class PropertyComparer&amp;lt;T&amp;gt;: IComparer&amp;lt;T&amp;gt;&lt;br /&gt;{&lt;br /&gt;  private readonly System.Reflection.PropertyInfo _propertyInfo;&lt;br /&gt;  private readonly string _sortDirection;&lt;br /&gt;&lt;br /&gt;  public PropertyComparer(string sortDirection, string propertyToSort)&lt;br /&gt;  {&lt;br /&gt;      _sortDirection = sortDirection;&lt;br /&gt;      _propertyInfo = typeof(T).GetProperty(propertyToSort, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.FlattenHierarchy | System.Reflection.BindingFlags.IgnoreCase);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  public int Compare(T x, T y)&lt;br /&gt;  {&lt;br /&gt;      object xValue = _propertyInfo.GetValue(x, null);&lt;br /&gt;      object yValue = _propertyInfo.GetValue(y, null);&lt;br /&gt;      if ((_sortDirection == "Ascending"))&lt;br /&gt;      {&lt;br /&gt;          return System.Collections.Comparer.Default.Compare(xValue, yValue);&lt;br /&gt;      }&lt;br /&gt;      else&lt;br /&gt;      {&lt;br /&gt;          return System.Collections.Comparer.Default.Compare(yValue, xValue);&lt;br /&gt;      }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;======================&lt;br /&gt;  protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;  {&lt;br /&gt;List&lt;/span&gt;&lt;span style=";font-family:trebuchet ms;font-size:85%;"  &gt;&amp;lt;&lt;/span&gt;&lt;span style=";font-family:trebuchet ms;font-size:85%;"  &gt;Task&lt;/span&gt;&lt;span style=";font-family:trebuchet ms;font-size:85%;"  &gt;&amp;gt;&lt;/span&gt;&lt;span style=";font-family:trebuchet ms;font-size:85%;"  &gt; test = new List&lt;/span&gt;&lt;span style=";font-family:trebuchet ms;font-size:85%;"  &gt;&amp;lt;&lt;/span&gt;&lt;span style=";font-family:trebuchet ms;font-size:85%;"  &gt;Task&lt;/span&gt;&lt;span style=";font-family:trebuchet ms;font-size:85%;"  &gt;&amp;gt;&lt;/span&gt;&lt;span style=";font-family:trebuchet ms;font-size:85%;"  &gt;();&lt;br /&gt;      Task ta = new Task();&lt;br /&gt;      ta.TaskName = "Scheduling";&lt;br /&gt;      ta.Description = "Start of the Scheduling process to schedule processing of transcripts and press releases");&lt;br /&gt;      test.Add(ta);&lt;br /&gt;      test.Sort(new PropertyComparer&amp;lt;Task&amp;gt;("Ascending","TaskName"));&lt;br /&gt;  }&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-188751464869463841?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/188751464869463841/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=188751464869463841' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/188751464869463841'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/188751464869463841'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2007/04/propertycomparer-for-sorting-arraylist.html' title='PropertyComparer&lt;T&gt; for SORTING a Generic List'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-5687086069546062706</id><published>2007-04-13T15:36:00.001-04:00</published><updated>2007-09-23T11:32:32.747-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='aspnet20'/><title type='text'>Recursive Find Control Code</title><content type='html'>&lt;pre&gt;&lt;span style="color: teal;"&gt;  1&lt;/span&gt; &lt;span style="color: blue;"&gt;public&lt;/span&gt; T FindControl&amp;lt;T&amp;gt;(&lt;span style="color: blue;"&gt;string&lt;/span&gt; id) where T : Control&lt;br /&gt;&lt;span style="color: teal;"&gt;  2&lt;/span&gt; {&lt;br /&gt;&lt;span style="color: teal;"&gt;  3&lt;/span&gt;     &lt;span style="color: blue;"&gt;return&lt;/span&gt; FindControl&amp;lt;T&amp;gt;(Page, id);&lt;br /&gt;&lt;span style="color: teal;"&gt;  4&lt;/span&gt; }&lt;br /&gt;&lt;span style="color: teal;"&gt;  5&lt;/span&gt;&lt;br /&gt;&lt;span style="color: teal;"&gt;  6&lt;/span&gt; &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;static&lt;/span&gt; T FindControl&amp;lt;T&amp;gt;(Control startingControl, &lt;span style="color: blue;"&gt;string&lt;/span&gt; id) where T : Control&lt;br /&gt;&lt;span style="color: teal;"&gt;  7&lt;/span&gt; {&lt;br /&gt;&lt;span style="color: teal;"&gt;  8&lt;/span&gt;     &lt;span style="color: green;"&gt;// this is null by default&lt;/span&gt;&lt;br /&gt;&lt;span style="color: teal;"&gt;  9&lt;/span&gt;     T found = &lt;span style="color: blue;"&gt;default&lt;/span&gt;(T);&lt;br /&gt;&lt;span style="color: teal;"&gt; 10&lt;/span&gt;&lt;br /&gt;&lt;span style="color: teal;"&gt; 11&lt;/span&gt;     &lt;span style="color: blue;"&gt;int&lt;/span&gt; controlCount = startingControl.Controls.Count;&lt;br /&gt;&lt;span style="color: teal;"&gt; 12&lt;/span&gt;&lt;br /&gt;&lt;span style="color: teal;"&gt; 13&lt;/span&gt;     &lt;span style="color: blue;"&gt;if&lt;/span&gt; (controlCount &amp;gt; &lt;span style="color: maroon;"&gt;0&lt;/span&gt;)&lt;br /&gt;&lt;span style="color: teal;"&gt; 14&lt;/span&gt;     {&lt;br /&gt;&lt;span style="color: teal;"&gt; 15&lt;/span&gt;         &lt;span style="color: blue;"&gt;for&lt;/span&gt; (&lt;span style="color: blue;"&gt;int&lt;/span&gt; i = &lt;span style="color: maroon;"&gt;0&lt;/span&gt;; i &amp;lt; controlCount; i++)&lt;br /&gt;&lt;span style="color: teal;"&gt; 16&lt;/span&gt;         {&lt;br /&gt;&lt;span style="color: teal;"&gt; 17&lt;/span&gt;             Control activeControl = startingControl.Controls[i];&lt;br /&gt;&lt;span style="color: teal;"&gt; 18&lt;/span&gt;             &lt;span style="color: blue;"&gt;if&lt;/span&gt; (activeControl &lt;span style="color: blue;"&gt;is&lt;/span&gt; T)&lt;br /&gt;&lt;span style="color: teal;"&gt; 19&lt;/span&gt;             {&lt;br /&gt;&lt;span style="color: teal;"&gt; 20&lt;/span&gt;                 found = startingControl.Controls[i] &lt;span style="color: blue;"&gt;as&lt;/span&gt; T;&lt;br /&gt;&lt;span style="color: teal;"&gt; 21&lt;/span&gt;                 &lt;span style="color: blue;"&gt;if&lt;/span&gt; (&lt;span style="color: blue;"&gt;string&lt;/span&gt;.Compare(id, found.ID, &lt;span style="color: maroon;"&gt;true&lt;/span&gt;) == &lt;span style="color: maroon;"&gt;0&lt;/span&gt;) &lt;span style="color: blue;"&gt;break&lt;/span&gt;;&lt;br /&gt;&lt;span style="color: teal;"&gt; 22&lt;/span&gt;                 &lt;span style="color: blue;"&gt;else&lt;/span&gt; found = &lt;span style="color: blue;"&gt;null&lt;/span&gt;;&lt;br /&gt;&lt;span style="color: teal;"&gt; 23&lt;/span&gt;             }&lt;br /&gt;&lt;span style="color: teal;"&gt; 24&lt;/span&gt;             &lt;span style="color: blue;"&gt;else&lt;/span&gt;&lt;br /&gt;&lt;span style="color: teal;"&gt; 25&lt;/span&gt;             {&lt;br /&gt;&lt;span style="color: teal;"&gt; 26&lt;/span&gt;                 found = FindControl&amp;lt;T&amp;gt;(activeControl, id);&lt;br /&gt;&lt;span style="color: teal;"&gt; 27&lt;/span&gt;                 &lt;span style="color: blue;"&gt;if&lt;/span&gt; (found != &lt;span style="color: blue;"&gt;null&lt;/span&gt;) &lt;span style="color: blue;"&gt;break&lt;/span&gt;;&lt;br /&gt;&lt;span style="color: teal;"&gt; 28&lt;/span&gt;             }&lt;br /&gt;&lt;span style="color: teal;"&gt; 29&lt;/span&gt;         }&lt;br /&gt;&lt;span style="color: teal;"&gt; 30&lt;/span&gt;     }&lt;br /&gt;&lt;span style="color: teal;"&gt; 31&lt;/span&gt;     &lt;span style="color: blue;"&gt;return&lt;/span&gt; found;&lt;br /&gt;&lt;span style="color: teal;"&gt; 32&lt;/span&gt; } &lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-5687086069546062706?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/5687086069546062706/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=5687086069546062706' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/5687086069546062706'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/5687086069546062706'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2007/04/recursive-find-control-code.html' title='Recursive Find Control Code'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-2865950195481650526</id><published>2007-04-12T14:46:00.000-04:00</published><updated>2007-04-12T14:47:32.172-04:00</updated><title type='text'>Enterprise Library 3.0</title><content type='html'>&lt;div style="font-family: courier new;" id="quickDescription"&gt;&lt;span style="font-size:85%;"&gt;This release of Enterprise Library includes: Caching Application Block, Cryptography Application Block, Data Access Application Block, Exception Handling Application Block, Logging Application Block, Policy Injection Application Block, Security Application Block and Validation Application Block.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-size:85%;"&gt;&lt;a style="font-family: courier new;" href="http://www.microsoft.com/downloads/details.aspx?FamilyID=62ef5f79-daf2-43af-9897-d926f03b9e60&amp;displaylang=en" target="_blank"&gt;Download here...&lt;/a&gt;&lt;span style="font-family: courier new;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-2865950195481650526?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/2865950195481650526/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=2865950195481650526' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/2865950195481650526'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/2865950195481650526'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2007/04/enterprise-library-30.html' title='Enterprise Library 3.0'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-2000990151562180167</id><published>2007-04-07T20:38:00.001-04:00</published><updated>2007-04-07T20:38:50.265-04:00</updated><title type='text'>dynamically hookup (hard code in global.asax) HTTP Modules</title><content type='html'>&lt;span style="font-size:85%;"&gt;one issue that has come up a few times is that the root site defines an HTTP module. The child virtual (an off the root virtual directory) when created by default inherits that module entry in web.config and usually fails because the module isn't available. Now it's easy to use a remove entry in your virtuals:&lt;br /&gt;&lt;br /&gt;add the following to your web.config file&lt;br /&gt;remove name="TopLevelModule"&lt;br /&gt;&lt;br /&gt;and that can usually take care of it. However, if you have many sub-virtuals you need to touch this can get tedious.&lt;br /&gt;So rather than fixing the Web.config in each subapplication I've removed the module definition in web.config and instead load the module via code. HttpModules hook up to the HttpApplication object of an ASP.NET application which is represented by your global.asax file in a Web project. HttpModules hook up to the events of this HttpApplication object, and since all a module really does is attach to the appropriate event handler in its Init() method there's no reason that you can't do this in code as well.&lt;br /&gt;There's one little gotcha though: It has to be done at just the right time in the HttpApplication life cycle which is when the HttpApplication object initializes (multiple times, once for each instance of HttpApplication). The only method where this works correct is HttpApplication Init().&lt;br /&gt;To hook up a module via code you can run code like the following instead of the HttpModule definition in web.config:&lt;br /&gt;&lt;br /&gt;public class Global : System.Web.HttpApplication&lt;br /&gt;{&lt;br /&gt;    public static xrnsToashxMappingModule Module = new xrnsToashxMappingModule();&lt;br /&gt;&lt;br /&gt;    public override void Init()&lt;br /&gt;    {&lt;br /&gt;        base.Init();&lt;br /&gt;        Module.Init(this);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;All you do is override the HttpApplication's Init() method and then access the static instance's Init method. Init() of the module hooks up the event and off you go.&lt;br /&gt;Note the use of HttpApplication Init; you might be tempted to use Application_Start, but that event is more like a static constructor that fires only once per Web application. Init() fires everytime a new application instance is initialized. Remember there are multiple HttpApplication instances executing side by side to handle simultaneous requests and each instance initializes separately.&lt;br /&gt;Using web.config is the preferred way of hooking up handles usually though for sure. But there are situations where you might not want to allow the module hookup to be dynamic. For example, if you have an application where the module is crucial to operation, performs some security feature, or version check, you might not want to allow removal of the module - this way it's a lot more difficult to disconnect the module. If you have a packaged application it can also be nice to have the set up hard coded in this fashion - one less thing to screw up during installation or when users start poking around in configuration files&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-2000990151562180167?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/2000990151562180167/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=2000990151562180167' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/2000990151562180167'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/2000990151562180167'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2007/04/dynamically-hookup-hard-code-in_61.html' title='dynamically hookup (hard code in global.asax) HTTP Modules'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-8283381049707605805</id><published>2007-03-22T10:51:00.000-04:00</published><updated>2007-03-22T10:52:55.830-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='aspnet20'/><title type='text'>Encrypt/Decrypt connection strings in web.config</title><content type='html'>&lt;span style="font-size:85%;"&gt;&lt;span style="font-family: courier new;"&gt;            const string PROVIDER = "DataProtectionConfigurationProvider";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;            const string PROVIDER = "RSAProtectedConfigurationProvider";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&lt;br /&gt;            Configuration ObjConfiguration =&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;             WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;            ConnectionStringsSection cnStrSettings = ObjConfiguration.ConnectionStrings;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: courier new;"&gt;            //Encrypt the Connection Strings Section&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;            cnStrSettings.SectionInformation.ProtectSection(PROVIDER);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;&lt;br /&gt;            //Decrypt the Connection Strings Section&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;            if (cnStrSettings.SectionInformation.IsProtected)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;            {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                cnStrSettings.SectionInformation.UnprotectSection();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;            ObjConfiguration.Save();&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-8283381049707605805?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/8283381049707605805/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=8283381049707605805' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/8283381049707605805'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/8283381049707605805'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2007/03/encryptdecrypt-connection-strings-in.html' title='Encrypt/Decrypt connection strings in web.config'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-5192419165204169831</id><published>2007-03-21T11:13:00.000-04:00</published><updated>2007-04-07T20:20:49.967-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sql2005'/><title type='text'>aspnet_regsql with SQLExpress database</title><content type='html'>&lt;p style="font-family: courier new;font-family:courier new;" &gt;&lt;span style="font-size:85%;"&gt;Creating a new DB in VisualStudio.NET 2005 is as simple as "&lt;strong&gt;Select APP_DATA node -&gt; Add New Item -&gt; Sql Database&lt;/strong&gt;" and wah-lah you have a new &lt;strong&gt;aspnet.mdf&lt;/strong&gt; file located in your APP_DATA folder.  However, when you run the tool &lt;strong&gt;ASPNET_REGSQL.exe&lt;/strong&gt; in Wizard Mode (E.g. using the "-W" switch) there is no way to specify a SQLEXPRESS attached database - it only seems to support SQL Server 2005 (and earlier) database servers.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-family: courier new;font-size:85%;" &gt;&lt;/span&gt;&lt;p style="font-family: courier new;font-family:courier new;" &gt;&lt;span style="font-size:85%;"&gt;So, after several attempts, I finally figured-out the "right" way to do this:&lt;/span&gt;&lt;/p&gt; &lt;p style="font-family: courier new;font-family:courier new;" &gt;&lt;span style="font-size:85%;"&gt;     aspnet_regsql -A all -C "Data Source=.\SQLEXPRESS;Integrated Security=True;User Instance=True" -d "C:\MyProject\APP_DATA\aspnetdb.mdf"&lt;/span&gt;&lt;/p&gt; &lt;span style="font-family: courier new;font-size:85%;" &gt;This will connect to the local SQLEXPRESS engine and attach the MDF file passed in the "-d" switch then create the appropriate objects in the DB.&lt;br /&gt;================================================================&lt;br /&gt;&lt;/span&gt;&lt;blockquote dir="ltr" style="margin-right: 0px; font-family: courier new;"&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;aspnet_regsql.exe -S &lt;em&gt;server&lt;/em&gt; -d &lt;em&gt;database&lt;/em&gt; -E -A all&lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p style="font-family: courier new;"&gt;&lt;span style="font-size:85%;"&gt;While this concept still applies for SQL Server 2005 Express Edition, it can be a little harder to get the server and database names right. What database server is SQL Server Express installed on? And what's the database name for a .MDF file in the App_Data&lt;/span&gt; folder?&lt;/p&gt; &lt;p style="font-family: courier new;"&gt;&lt;span style="font-size:85%;"&gt;Assuming you are working on an ASP.NET application locally, the server name will be: &lt;strong&gt;localhost\SQLExpress&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="font-family: courier new;"&gt;&lt;span style="font-size:85%;"&gt;The database name is (and here's it can get a bit tricky), is the path to the MDF file &lt;em&gt;when it was created&lt;/em&gt;. So, say that you have an ASP.NET application created in the classroom lab at C:\Labs\Website\App_Data\MessageBoard.mdf. The name of the database is C:\Labs\Website\App_Data\MessageBoard.mdf, meaning you could install the membership services from the command-line using:&lt;/span&gt;&lt;/p&gt; &lt;blockquote dir="ltr" style="margin-right: 0px; font-family: courier new;"&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;aspnet_regsql.exe -S localhost\SQLExpress -d “C:\Labs\Website\App_Data\MessageBoard.mdf” -E -A all&lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p style="font-family: courier new;"&gt;&lt;span style="font-size:85%;"&gt;Now, imagine that you zip up your files onto a USB keychain drive, go home, and copy your project files to C:\Home\Website. Now, if you wanted to create the services, you'd think you'd just type in:&lt;/span&gt;&lt;/p&gt; &lt;blockquote dir="ltr" style="margin-right: 0px; font-family: courier new;"&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;aspnet_regsql.exe -S localhost\SQLExpress -d “C:\Home\Website\App_Data\MessageBoard.mdf” -E -A all&lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p style="font-family: courier new;"&gt;&lt;span style="font-size:85%;"&gt;Ah, but the database name is C:\&lt;strong&gt;&lt;span style="color:#ff0000;"&gt;Labs&lt;/span&gt;&lt;/strong&gt;\Website\App_Data\MessageBoard.mdf. Eep. So when you run the above command the database can't be found and cryptic error messages abound. Essentially, it can't find the database C:\Home\Website\App_Data\MessageBoard.mdf so it tries to create a database file in the default directory (&lt;em&gt;%PROGRAM FILES%&lt;/em&gt;\Microsoft SQL Server\MSSQL.1\DATA) with the filename C:\Home\Website\App_Data\MessageBoard.mdf. This, of course, causes problems since that's not a valid filename. Ick.&lt;/span&gt;&lt;/p&gt; &lt;p style="font-family: courier new;"&gt;&lt;span style="font-size:85%;"&gt;So how do we fix this? There are a couple optios. The easiest is probably to download the (free) &lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=82afbd59-57a4-455e-a2d6-1d4c98d40f6e&amp;displaylang=en"&gt;SQL Server 2005 Management Studio &lt;em&gt;Express&lt;/em&gt; program&lt;/a&gt; and attach the database file. Then, from the Properties pane you can see the database name. You can then use this with aspnet_regsql.exe. (You could also rename the database at this point...)&lt;/span&gt;&lt;/p&gt; &lt;p style="font-family: courier new;"&gt;&lt;span style="font-size:85%;"&gt;If you want to be 3l33t you can use &lt;a href="http://msdn2.microsoft.com/en-us/library/ms165702%28SQL.90%29.aspx"&gt;sqlcmd&lt;/a&gt;, attach the database (sp_attach_db) giving it a friendly name, which you can then use to run the aspnet_regsql.exe command line program against. Something like:&lt;/span&gt;&lt;/p&gt; &lt;blockquote dir="ltr" style="margin-right: 0px; font-family: courier new;"&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;sqlcmd -S localhost\SQLExpress -Q “EXEC sp_attach_db 'Foobar', N'&lt;em&gt;pathToDBfile&lt;/em&gt;'”&lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p style="font-family: courier new;"&gt;&lt;span style="font-size:85%;"&gt;And then:&lt;/span&gt;&lt;/p&gt; &lt;blockquote dir="ltr" style="margin-right: 0px; font-family: courier new;"&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;aspnet_regsql.exe -S localhost\SQLExpress -d Foobar -E -A all&lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-5192419165204169831?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/5192419165204169831/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=5192419165204169831' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/5192419165204169831'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/5192419165204169831'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2007/03/aspnetregsql-with-sqlexpress-database.html' title='aspnet_regsql with SQLExpress database'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-902766006117643969</id><published>2007-03-13T11:17:00.000-04:00</published><updated>2007-03-13T11:18:26.389-04:00</updated><title type='text'>Adding Asc/Desc Icon on Table Headers for Sorting</title><content type='html'>&lt;span style="font-size:85%;"&gt;&lt;span style="font-family: courier new;"&gt;ListItemType itemType = (ListItemType)e.Item.ItemType;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;// Don't bother too much for the footer, and separator items&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;if(itemType == ListItemType.Separator || itemType == ListItemType.Footer)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;{                &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;else if (itemType == ListItemType.Header)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;TableCell TCell;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;if(TCell != null)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;// make a new label &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;Label sortSymbol = new Label();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;sortSymbol.Font.Name = "Webdings";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;sortSymbol.Font.Size = 10;                    &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;if(this.SortAscend == "Asc")&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    // Ascending&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    sortSymbol.Text = "5";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    sortSymbol.ForeColor = System.Drawing.Color.Red;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    theCell.Controls.AddAt(0, sortSymbol);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;else&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    // Descending&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    sortSymbol.Text = "6";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    sortSymbol.ForeColor = System.Drawing.Color.Blue;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    theCell.Controls.Add(sortSymbol);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;}            &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-902766006117643969?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/902766006117643969/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=902766006117643969' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/902766006117643969'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/902766006117643969'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2007/03/adding-ascdesc-icon-on-table-headers.html' title='Adding Asc/Desc Icon on Table Headers for Sorting'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-4182405997070864557</id><published>2007-03-09T10:37:00.001-05:00</published><updated>2007-03-09T10:37:51.281-05:00</updated><title type='text'>SPLIT function - TSQL</title><content type='html'>&lt;span style="font-size:85%;"&gt;&lt;span style="font-family: courier new;"&gt;CREATE FUNCTION SPLIT (&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;@str_in        VARCHAR(8000),&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;@separator    VARCHAR(4) )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;RETURNS @strtable TABLE (strval        VARCHAR(8000))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;AS&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;BEGIN&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;DECLARE&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    @Occurrences    INT,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    @Counter    INT,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    @tmpStr    VARCHAR(8000)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    SET @Counter = 0&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;        IF SUBSTRING(@str_in,LEN(@str_in),1) &lt;&gt; @separator &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;              SET @str_in = @str_in + @separator&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    SET @Occurrences = (DATALENGTH(REPLACE(@str_in,@separator,@separator+'#')) -  DATALENGTH(@str_in))/ DATALENGTH(@separator)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    SET @tmpStr    = @str_in&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    WHILE @Counter &lt;= @Occurrences &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    BEGIN&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;        SET @Counter = @Counter + 1&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;        INSERT INTO @strtable&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;        VALUES ( SUBSTRING(@tmpStr,1,CHARINDEX(@separator,@tmpStr)-1))&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;        SET @tmpStr = SUBSTRING(@tmpStr,CHARINDEX(@separator,@tmpStr)+1,8000)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;        &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;        IF DATALENGTH(@tmpStr) = 0&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;            BREAK&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;        &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    END&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    RETURN &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;END&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-4182405997070864557?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/4182405997070864557/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=4182405997070864557' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/4182405997070864557'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/4182405997070864557'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2007/03/split-function-tsql.html' title='SPLIT function - TSQL'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-6625125537134486868</id><published>2007-03-08T11:45:00.000-05:00</published><updated>2007-11-27T17:49:30.090-05:00</updated><title type='text'>Encryption in SQL2005</title><content type='html'>&lt;span style=";font-family:Arial;font-size:100%;"  &gt;I found this nice article on Encryption in SQL2005.&lt;br /&gt;&lt;br /&gt;http://www.databasejournal.com/features/mssql/article.php/3461471 - Authentication&lt;br /&gt;http://www.databasejournal.com/features/mssql/article.php/3481751 - Authorization&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;  &lt;p class="MsoNormal"  style="font-family:courier new;"&gt;&lt;span style="font-size:100%;"&gt;&lt;a href="http://www.databasejournal.com/features/mssql/article.php/3483931"&gt;http://www.databasejournal.com/features/mssql/article.php/3483931 - Encryption&lt;br /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="font-family:courier new;"&gt;&lt;span style="font-size:100%;"&gt;&lt;a href="http://www.databasejournal.com/features/mssql/article.php/3483931"&gt;http://www.databasejournal.com/features/mssql/article.php/3488046 - Security&lt;br /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"  style="font-family:courier new;"&gt;&lt;span style="font-size:100%;"&gt;http://www.sqlservercentral.com/articles/SQL+Server+2005+-+Security/3058/&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal"  style="font-family:courier new;"&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;As a matter of fact we already have password hashing capability in SQL2000 itself, the PWDENCRYPT function is available to create a one-way hash.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="font-family:courier new;"&gt;&lt;span style="font-size:100%;"&gt;In 2005 there are the EncryptByKey, EncryptByCert, EncryptByAsmKey and EncryptByPassPhrase methods that can be used for encrypting data.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="font-family:courier new;"&gt;&lt;span style="font-size:100%;"&gt;For passwords the encryptByCert / EncryptByAsmKey or EncryptByPassPhrase can used which provide enough security.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="font-family:courier new;"&gt;&lt;span style="font-size:100%;"&gt;EncryptByKey is symmetric key encryption which is usually combined with Certificates to encrypt the Symmetric key used for encypting large amounts data.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style=";font-family:Arial;font-size:100%;"  &gt;At the root level is the Service Master key which is automatically created during SQL2005 installation.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;  &lt;p class="MsoNormal"  style="font-family:courier new;"&gt;&lt;span style="font-size:100%;"&gt;Then we have a Database Master Key which needs to be created using DDL statements for each Database on the SQL Server Instance. The database master key is created using the service master key along with an optional password.&lt;/span&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;create master key encryption by password = 'SecretPassword' ----this creates the DB master key&lt;/li&gt;&lt;li&gt;create certificate rbg_cert with subject = 'cert for rbg' ----creates a certificate using the DB Master key&lt;/li&gt;&lt;li&gt;create certificate rbg_cert encryption by password = 'secret' with subject = 'cert for rohit' ----- this creates a certificate using password as the Private Key instead of the DB master key.&lt;/li&gt;&lt;li&gt;create user rbg for certificate rbg_cert ----- creates the PROXY user&lt;/li&gt;&lt;li&gt;create login rbg_login from certificate rbg_cert --- creates a SQL login -- note logins are created in master DB, thus a rbg_cert should exist in master DB before you can run this command&lt;/li&gt;&lt;/ul&gt;Important system tables are&lt;ol&gt;&lt;li&gt;sys.symmetric_keys - stores master and symmetric keys&lt;/li&gt;&lt;li&gt;sys.databases --- list of all db's in the server&lt;/li&gt;&lt;li&gt;sys.certificates -- lists certificates in a &lt;span style="font-weight: bold;"&gt;particular &lt;/span&gt;DB&lt;/li&gt;&lt;li&gt;sysusers --- lists users in a particular DB, syslogins --- all logins&lt;br /&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p class="MsoNormal"  style="font-family:courier new;"&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"  style="font-family:courier new;"&gt;&lt;span style="font-size:100%;"&gt;Then Certificates and Asymmetric keys are created using the database Master key and then we use the Encryption functions to encrypt and decrypt data/passwords. The EncryptByKey and EncryptByPassPhrase are symmetric encryption mechanisms which do not involve using the Database master key&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-6625125537134486868?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/6625125537134486868/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=6625125537134486868' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/6625125537134486868'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/6625125537134486868'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2007/03/encryption-in-sql2005.html' title='Encryption in SQL2005'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-3283153528117854113</id><published>2007-03-01T11:02:00.000-05:00</published><updated>2007-03-01T11:12:39.017-05:00</updated><title type='text'>Script to Temporarily disable and enable constraints</title><content type='html'>&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="font-weight: bold;" class="MsoNormal"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;http://vyaskn.tripod.com/generate_scripts_repetitive_sql_tasks.htm#s4&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#408080;"&gt;&lt;span style="font-size: 10pt; color: rgb(64, 128, 128); font-family: 'Courier New';"&gt;/*To disable  constraints*/&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:blue;"&gt;&lt;span style="font-size: 10pt; color: blue; font-family: 'Courier New';"&gt;&lt;br /&gt;SELECT  'ALTER TABLE ' + QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME) + '  NOCHECK CONSTRAINT ALL'&lt;br /&gt;FROM INFORMATION_SCHEMA.TABLES&lt;br /&gt;WHERE &lt;br /&gt;OBJECTPROPERTY(OBJECT_ID(QUOTENAME(TABLE_SCHEMA) + '.' +  QUOTENAME(TABLE_NAME)), 'IsMSShipped') = 0&lt;br /&gt;AND TABLE_TYPE = 'BASE  TABLE'&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#408080;"&gt;&lt;span style="font-size: 10pt; color: rgb(64, 128, 128); font-family: 'Courier New';"&gt;--AND  TABLE_SCHEMA = 'Admin1' /*To disable constraints on tables owned by 'Admin1'  only*/&lt;br /&gt;--AND TABLE_NAME LIKE 'Tbl%' /*To disable constraints on tables  starting with a particular pattern*/&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:blue;"&gt;&lt;span style="font-size: 10pt; color: blue; font-family: 'Courier New';"&gt;&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#408080;"&gt;&lt;span style="font-size: 10pt; color: rgb(64, 128, 128); font-family: 'Courier New';"&gt;/*To enable  constraints*/&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:blue;"&gt;&lt;span style="font-size: 10pt; color: blue; font-family: 'Courier New';"&gt;SELECT 'ALTER  TABLE ' + QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME) + ' CHECK  CONSTRAINT ALL'&lt;br /&gt;FROM INFORMATION_SCHEMA.TABLES&lt;br /&gt;WHERE &lt;br /&gt;OBJECTPROPERTY(OBJECT_ID(QUOTENAME(TABLE_SCHEMA) + '.' +  QUOTENAME(TABLE_NAME)), 'IsMSShipped') = 0&lt;br /&gt;AND TABLE_TYPE = 'BASE  TABLE'&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:#408080;"&gt;&lt;span style="font-size: 10pt; color: rgb(64, 128, 128); font-family: 'Courier New';"&gt;--AND  TABLE_SCHEMA = 'Admin1' /*To enable constraints on tables owned by 'Admin1'  only*/&lt;br /&gt;--AND TABLE_NAME LIKE 'Tbl%' /*To enable constraints on tables  starting with a particular pattern*/&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Courier New;font-size:85%;color:blue;"&gt;&lt;span style="font-size: 10pt; color: blue; font-family: 'Courier New';"&gt;&lt;br /&gt;GO&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-3283153528117854113?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/3283153528117854113/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=3283153528117854113' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/3283153528117854113'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/3283153528117854113'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2007/03/script-to-temporarily-disable-and.html' title='Script to Temporarily disable and enable constraints'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-5439946342719839192</id><published>2007-03-01T10:58:00.000-05:00</published><updated>2007-03-01T11:02:55.681-05:00</updated><title type='text'>Quick Search within all stored procedures</title><content type='html'>&lt;span style="font-size:85%;"&gt;&lt;span style="color: rgb(51, 51, 255); font-family: courier new;"&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;/* Method 1 :: For Master Database */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Select&lt;br /&gt; distinct(SO.[name]) as 'Stored Procedure Name'&lt;br /&gt;From&lt;br /&gt; SysComments SC,&lt;br /&gt; SysObjects SO&lt;br /&gt;Where&lt;br /&gt; SO.ID = SC.ID and&lt;br /&gt; cateGory &lt;&gt; 2 and&lt;br /&gt; PatIndex( @searchString, text) &gt; 0&lt;br /&gt;Order By&lt;br /&gt; [name]&lt;br /&gt;End&lt;br /&gt;Else&lt;br /&gt;Begin&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;/* Method 2 :: For Individual Database&lt;br /&gt;Double check whether you have removed the prefix "sp_" from the SP name.&lt;br /&gt;*/&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Select&lt;br /&gt; Routine_Name as 'Stored Procedure Name'&lt;br /&gt;From&lt;br /&gt; InformatiOn_Schema.Routines&lt;br /&gt;Where&lt;br /&gt; Routine_type = 'procedure' and&lt;br /&gt; ObjectProperty(Object_Id(Routine_Name),'IsMsShipped') = 0 and&lt;br /&gt; PatIndex( @searchString, Routine_DefinitiOn) &gt; 0&lt;br /&gt;End&lt;br /&gt;&lt;br /&gt;If @@Error &lt;&gt; 0&lt;br /&gt;Return (1)&lt;br /&gt;Return 0&lt;br /&gt;Go&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-5439946342719839192?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/5439946342719839192/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=5439946342719839192' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/5439946342719839192'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/5439946342719839192'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2007/03/quick-search-within-all-stored.html' title='Quick Search within all stored procedures'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-7589208273607956254</id><published>2007-03-01T10:53:00.000-05:00</published><updated>2007-03-01T10:54:35.161-05:00</updated><title type='text'>sp_executesql for dynamic stored procedures with parameters</title><content type='html'>&lt;span style="font-family: courier new;font-size:85%;" &gt;    DECLARE @sql nvarchar(2000)&lt;br /&gt;&lt;br /&gt;    DECLARE @param nvarchar(400)&lt;br /&gt;&lt;br /&gt;    SET @param = N' @ProductID INT, @ProductInventoryStatusID INT, @ManagedByPersonID INT'&lt;br /&gt;&lt;br /&gt;    SET @sql = N' INSERT INTO #tbRangesStart&lt;br /&gt;      SELECT DISTINCT t1.serialnumber&lt;br /&gt;        FROM productinventory t1&lt;br /&gt;            LEFT OUTER JOIN productinventory t2 ON t1.serialnumber - 1 = t2.serialnumber  AND t1.productid=t2.productid&lt;br /&gt;        WHERE '&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    DECLARE @where nvarchar(1000)&lt;br /&gt;&lt;br /&gt;    IF @ProductID IS NOT NULL&lt;br /&gt;    SET @where = N' t1.productid = @ProductID AND'&lt;br /&gt;    ELSE&lt;br /&gt;    SET @where = N' '&lt;br /&gt;&lt;br /&gt;    IF     @ProductInventoryStatusID IS NULL and @ManagedByPersonID IS NULL&lt;br /&gt;    SET @where = @where + N' t2.serialnumber is null ORDER BY t1.serialnumber'&lt;br /&gt;&lt;br /&gt;    IF     @ProductInventoryStatusID IS NOT NULL and @ManagedByPersonID IS NULL&lt;br /&gt;    SET @where = @where +  N' t1.productinventorystatusid = @ProductInventoryStatusID AND (t2.serialnumber is null OR (t1.productinventorystatusid = @ProductInventoryStatusID AND t2.productinventorystatusid &lt;&gt; @ProductInventoryStatusID)) ORDER BY t1.serialnumber'&lt;br /&gt;&lt;br /&gt;    IF     @ProductInventoryStatusID IS NULL and @ManagedByPersonID IS NOT NULL&lt;br /&gt;    SET @where = @where +  N' t1.ManagedByPersonID = @ManagedByPersonID AND (t2.serialnumber is null OR (t1.ManagedByPersonID = @ManagedByPersonID AND t2.ManagedByPersonID &lt;&gt; @ManagedByPersonID)) ORDER BY t1.serialnumber'   &lt;br /&gt;&lt;br /&gt;    IF     @ProductInventoryStatusID IS NOT NULL and @ManagedByPersonID IS NOT NULL&lt;br /&gt;    SET @where = @where + N' t1.productinventorystatusid = @ProductInventoryStatusID AND t1.ManagedByPersonID = @ManagedByPersonID AND (t2.serialnumber is null OR (t1.productinventorystatusid = @ProductInventoryStatusID AND t2.productinventorystatusid &lt;&gt; @ProductInventoryStatusID) OR (t1.ManagedByPersonID = @ManagedByPersonID AND t2.ManagedByPersonID &lt;&gt; @ManagedByPersonID)) ORDER BY t1.serialnumber'   &lt;br /&gt;&lt;br /&gt;    SET @sql = @sql + @where&lt;br /&gt;    EXEC sp_executesql @sql, @PARAM, @ProductID, @ProductInventoryStatusID, @ManagedByPersonID&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-7589208273607956254?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/7589208273607956254/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=7589208273607956254' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/7589208273607956254'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/7589208273607956254'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2007/03/spexecutesql-for-dynamic-stored.html' title='sp_executesql for dynamic stored procedures with parameters'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-3022880342833637185</id><published>2007-03-01T10:45:00.000-05:00</published><updated>2007-03-01T10:47:29.775-05:00</updated><title type='text'>Insert Rows Generator</title><content type='html'>This stored proc is used to generate INSERT STATEMENTS for inserting rows into a Table:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:78%;"&gt;CREATE PROC sp_InsertGenerator&lt;br /&gt;(@tableName varchar(100)) as&lt;br /&gt;--Declare a cursor to retrieve column specific information for the specified table&lt;br /&gt;DECLARE cursCol CURSOR FAST_FORWARD FOR&lt;br /&gt;SELECT column_name,data_type FROM information_schema.columns WHERE table_name = @tableName&lt;br /&gt;OPEN cursCol&lt;br /&gt;DECLARE @string nvarchar(4000) --for storing the first half of INSERT statement&lt;br /&gt;DECLARE @stringData nvarchar(4000) --for storing the data (VALUES) related statement&lt;br /&gt;DECLARE @dataType nvarchar(1000) --data types returned for respective columns&lt;br /&gt;SET @string='INSERT '+@tableName+'('&lt;br /&gt;SET @stringData=''&lt;br /&gt;DECLARE @colName nvarchar(50)&lt;br /&gt;FETCH NEXT FROM cursCol INTO @colName,@dataType&lt;br /&gt;IF @@fetch_status&lt;&gt;0&lt;br /&gt;    begin&lt;br /&gt;    print 'Table '+@tableName+' not found, processing skipped.'&lt;br /&gt;    close curscol&lt;br /&gt;    deallocate curscol&lt;br /&gt;    return&lt;br /&gt;END&lt;br /&gt;WHILE @@FETCH_STATUS=0&lt;br /&gt;BEGIN&lt;br /&gt;IF @dataType in ('varchar','char','nchar','nvarchar')&lt;br /&gt;BEGIN&lt;br /&gt;    SET @stringData=@stringData+'''''''''+isnull('+@colName+','''')+'''''',''+'&lt;br /&gt;END&lt;br /&gt;ELSE&lt;br /&gt;if @dataType in ('text','ntext') --if the datatype is text or something else&lt;br /&gt;BEGIN&lt;br /&gt;    SET @stringData=@stringData+'''''''''+isnull(cast('+@colName+' as varchar(2000)),'''')+'''''',''+'&lt;br /&gt;END&lt;br /&gt;ELSE&lt;br /&gt;IF @dataType = 'money' --because money doesn't get converted from varchar implicitly&lt;br /&gt;BEGIN&lt;br /&gt;    SET @stringData=@stringData+'''convert(money,''''''+isnull(cast('+@colName+' as varchar(200)),''0.0000'')+''''''),''+'&lt;br /&gt;END&lt;br /&gt;ELSE&lt;br /&gt;IF @dataType='datetime'&lt;br /&gt;BEGIN&lt;br /&gt;    SET @stringData=@stringData+'''convert(datetime,''''''+isnull(cast('+@colName+' as varchar(200)),''0'')+''''''),''+'&lt;br /&gt;END&lt;br /&gt;ELSE&lt;br /&gt;IF @dataType='image'&lt;br /&gt;BEGIN&lt;br /&gt;    SET @stringData=@stringData+'''''''''+isnull(cast(convert(varbinary,'+@colName+') as varchar(6)),''0'')+'''''',''+'&lt;br /&gt;END&lt;br /&gt;ELSE --presuming the data type is int,bit,numeric,decimal&lt;br /&gt;BEGIN&lt;br /&gt;    SET @stringData=@stringData+'''''''''+isnull(cast('+@colName+' as varchar(200)),''0'')+'''''',''+'&lt;br /&gt;END&lt;br /&gt;SET @string=@string+@colName+','&lt;br /&gt;FETCH NEXT FROM cursCol INTO @colName,@dataType&lt;br /&gt;END&lt;br /&gt;DECLARE @Query nvarchar(4000)&lt;br /&gt;SET @query ='SELECT '''+substring(@string,0,len(@string)) + ') VALUES(''+ ' + substring(@stringData,0,len(@stringData)-2)+'''+'')'' FROM '+@tableName&lt;br /&gt;print @query&lt;br /&gt;--exec sp_executesql @query&lt;br /&gt;CLOSE cursCol&lt;br /&gt;DEALLOCATE cursCol&lt;br /&gt;GO&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-3022880342833637185?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/3022880342833637185/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=3022880342833637185' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/3022880342833637185'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/3022880342833637185'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2007/03/insert-rows-generator.html' title='Insert Rows Generator'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-5819414367494591915</id><published>2007-03-01T10:41:00.000-05:00</published><updated>2007-03-01T10:45:29.564-05:00</updated><title type='text'>Generating a range of Serial numbers in TSQL</title><content type='html'>&lt;span style="font-size:78%;"&gt;The following helps in automatically generating a range of SerialNumbers in sequence:&lt;br /&gt;&lt;br /&gt;DECLARE @SerialNumberStart INT&lt;br /&gt;DECLARE @SerialNumberEnd INT&lt;br /&gt;SELECT &lt;/span&gt;&lt;span style="font-size:78%;"&gt;SerialNumberStart  = 99900, &lt;/span&gt;&lt;span style="font-size:78%;"&gt;SerialNumberEnd= 99999&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:78%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:78%;"&gt;        DECLARE @tbNumberBase            TABLE&lt;br /&gt;        (&lt;br /&gt;            Seq                INT&lt;br /&gt;        )&lt;br /&gt;        INSERT INTO @tbNumberBase&lt;br /&gt;            SELECT digits FROM (SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9)&lt;br /&gt;            Dig (digits)&lt;br /&gt;        INSERT INTO ProductInventory&lt;br /&gt;        (           &lt;br /&gt;            ProductID,&lt;br /&gt;            SerialNumber,&lt;br /&gt;            Quantity       &lt;br /&gt;        )&lt;br /&gt;        SELECT&lt;br /&gt;            @ProductID,&lt;br /&gt;            SerialNumber,&lt;br /&gt;            @Quantity&lt;br /&gt;        FROM&lt;br /&gt;            (SELECT&lt;br /&gt;                    @SerialNumberStart&lt;br /&gt;                    + HundredThousands.Seq * 100000&lt;br /&gt;                    + TenThousands.Seq * 10000&lt;br /&gt;                    + Thousands.Seq * 1000&lt;br /&gt;                    + Hundreds.Seq * 100&lt;br /&gt;                    + Tens.Seq * 10&lt;br /&gt;                    + Units.Seq Num&lt;br /&gt;            FROM&lt;br /&gt;                @tbNumberBase HundredThousands&lt;br /&gt;                CROSS JOIN @tbNumberBase TenThousands&lt;br /&gt;                CROSS JOIN @tbNumberBase Thousands&lt;br /&gt;                CROSS JOIN @tbNumberBase Hundreds&lt;br /&gt;                CROSS JOIN @tbNumberBase Tens&lt;br /&gt;                CROSS JOIN @tbNumberBase Units)&lt;br /&gt;            TableAlias (SerialNumber)&lt;br /&gt;        WHERE SerialNumber &lt;= @SerialNumberEnd&lt;br /&gt;        ORDER BY SerialNumber&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-5819414367494591915?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/5819414367494591915/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=5819414367494591915' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/5819414367494591915'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/5819414367494591915'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2007/03/generating-range-of-serial-numbers-in.html' title='Generating a range of Serial numbers in TSQL'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-6165899031501211446</id><published>2007-03-01T10:33:00.000-05:00</published><updated>2007-03-01T10:36:23.168-05:00</updated><title type='text'>Parameterized Properties in C#</title><content type='html'>&lt;span style="font-size:78%;"&gt;To create Parameterized Properties in C# one can only use a Indexer (the default parameterized property... this[]). However if we wanted to store an array of a particular type one could use the following which would be a parameterized property itself.:&lt;br /&gt;&lt;br /&gt;        public string[] CardsDescription&lt;br /&gt;        {&lt;br /&gt;            get&lt;br /&gt;            {&lt;br /&gt;                if (this.ViewState["CardsDescription"] == null)&lt;br /&gt;                {&lt;br /&gt;                    this.ViewState["CardsDescription"] = new System.String[3];&lt;br /&gt;                    return (string[])this.ViewState["CardsDescription"];&lt;br /&gt;                }&lt;br /&gt;                else&lt;br /&gt;                    return (string[])this.ViewState["CardsDescription"];&lt;br /&gt;            }&lt;br /&gt;            set&lt;br /&gt;            {&lt;br /&gt;                this.ViewState["CardsDescription"] = value;&lt;br /&gt;            }&lt;br /&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Thus when setting values you would use&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:78%;"&gt;            int index = 0;&lt;br /&gt;            foreach(System.Data.DataRow dr in productDT.Rows)&lt;br /&gt;            {&lt;br /&gt;                int productID = int.Parse(dr["ProductID"].ToString());&lt;br /&gt;&lt;br /&gt;                this.CardsDescription[index] = dr["Description"].ToString();&lt;br /&gt;&lt;br /&gt;                index += 1;&lt;br /&gt;            }&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-6165899031501211446?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/6165899031501211446/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=6165899031501211446' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/6165899031501211446'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/6165899031501211446'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2007/03/parameterized-properties-in-c.html' title='Parameterized Properties in C#'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-2483180054926498266</id><published>2007-02-06T12:37:00.000-05:00</published><updated>2007-02-06T12:37:19.329-05:00</updated><title type='text'>ASP.NET 2.0 Tips and Tricks and ASP.NET, IIS7 and ASP.NET AJAX End to End Talks</title><content type='html'>&lt;a href="http://weblogs.asp.net/scottgu/archive/2007/02/05/asp-net-2-0-tips-and-tricks-and-asp-net-iis7-and-asp-net-ajax-end-to-end-talks.aspx"&gt;&lt;/a&gt;&lt;p&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;strong&gt;ASP.NET Tips and Tricks:&lt;/strong&gt;  &lt;/span&gt;&lt;/p&gt;&lt;span style="font-family:arial;font-size:85%;"&gt; &lt;/span&gt;&lt;p&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;This talk covered ASP.NET UI, AJAX, Caching and Deployment Tips and Tricks, and Visual Studio 2005 tips/tricks.  The samples include updated versions of ASP.NET AJAX that all work with ASP.NET AJAX 1.0.  You can download the slides+samples &lt;a href="http://www.scottgu.com/BlogPosts/Europe_Feb07/TipsAndTricks_Belgium.zip" target="_blank"&gt;here&lt;/a&gt;.&lt;/span&gt;&lt;/p&gt;&lt;span style="font-family:arial;font-size:85%;"&gt; &lt;/span&gt;&lt;p&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;You can learn more about the Visual Studio build performance optimization suggestions by &lt;a href="http://weblogs.asp.net/scottgu/archive/2006/09/22/Tip_2F00_Trick_3A00_-Optimizing-ASP.NET-2.0-Web-Project-Build-Performance-with-VS-2005.aspx"&gt;reading this past post of mine on improving build performance&lt;/a&gt;.  You can also find several dozen more ASP.NET and Visual Studio Tips/Tricks of mine on &lt;a href="http://weblogs.asp.net/scottgu/pages/ASP.NET-2.0-Tips_2C00_-Tricks_2C00_-Recipes-and-Gotchas.aspx"&gt;my Tips and Tricks summary page&lt;/a&gt;.  &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;strong&gt;Building an End-to-end Web Application from scratch using ASP.NET 2.0, ASP.NET AJAX, IIS7 and Visual Studio:&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-family:arial;font-size:85%;"&gt; &lt;/span&gt;&lt;p&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;This talk walked through building a rich data-driven application from scratch using ASP.NET 2.0, ASP.NET AJAX 1.0, IIS7 and Visual Studio (all of which are now officially shipping products).  You can download the deck + completed sample &lt;a href="http://www.scottgu.com/BlogPosts/Europe_Feb07/reading.zip" target="_blank"&gt;here&lt;/a&gt;.&lt;/span&gt;&lt;/p&gt;&lt;span style="font-family:arial;font-size:85%;"&gt; &lt;/span&gt;&lt;p&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;This talk demonstrates the following features: IIS7 distributed configuration, Master Pages, Building a DAL using DataSets, Building Data Driven Edit Pages, Building Catalogue Browsing Pages, Site Navigation, Url Rewriting, Site Navigation, CSS Control Adapters, ASP.NET AJAX, ASP.NET AJAX Control Toolkit, Membership/Roles, IIS7 Admin UI, SQL Cache Invalidation, and WebPart portal support.&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-2483180054926498266?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://weblogs.asp.net/scottgu/archive/2007/02/05/asp-net-2-0-tips-and-tricks-and-asp-net-iis7-and-asp-net-ajax-end-to-end-talks.aspx' title='ASP.NET 2.0 Tips and Tricks and ASP.NET, IIS7 and ASP.NET AJAX End to End Talks'/><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/2483180054926498266/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=2483180054926498266' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/2483180054926498266'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/2483180054926498266'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2007/02/aspnet-20-tips-and-tricks-and-aspnet.html' title='ASP.NET 2.0 Tips and Tricks and ASP.NET, IIS7 and ASP.NET AJAX End to End Talks'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-2989851836788232674</id><published>2007-02-02T10:38:00.000-05:00</published><updated>2007-02-02T10:38:37.510-05:00</updated><title type='text'>transaction isolation levels</title><content type='html'>&lt;h2&gt;SQL Server concepts - transaction isolation levels &lt;/h2&gt;    &lt;div class="postcontent"&gt;   &lt;p&gt;&lt;span style="font-family:Arial;font-size:85%;color:#000080;"&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;While preparing some stuff around SQL Server 2005, I thought it was the ideal occasion to do some blog posts about the SQL Server 2000/2005 architecture and several concepts. In this post I'll cover transaction isolation levels, later I'll post more about transactions while talking about the new System.Transactions namespace. However, let's start by taking a look at transaction stuff inside the database itself.&lt;/span&gt;&lt;/p&gt; &lt;p&gt; &lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Arial;font-size:85%;color:#000080;"&gt;&lt;strong&gt;Transactions: a short definition&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Tons of people have given a definition of a transaction before me, so I won't cover this in much detail. I'll just try to give a definition for a transaction in order to create some context for further elaboration. Basically, a transaction is a set of statements (in our case database statements) that have to be executed in an &lt;strong&gt;atomic&lt;/strong&gt; fashion (either all of the statements succeed, or all of them fail together). Next, there's the &lt;strong&gt;consistency&lt;/strong&gt; property, which means that a transaction should bring the system from one consistent state to another consistent state. During the transaction, &lt;strong&gt;isolation&lt;/strong&gt; has to be maintained. This means a transaction is out there on its own, it can't see what others are doing. &lt;em&gt;Locking&lt;/em&gt; will be used to accomplish these requirements, as I'll explain in a moment. Last but not least, there's the &lt;strong&gt;durability&lt;/strong&gt; property. A transaction can finish either by a commit (changes are allowed) or a rollback (changes are rolled back to the last consistent state). Durability means that when a transaction is committed, the changes made to the database should be persistent even a disaster occurs one processor cycle after the transaction commit.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;The grouping of these four properties is abbreviated as the &lt;strong&gt;ACID&lt;/strong&gt; properties. Transactions play a central role in database technology, especially in multi-user environments. A classic example of a transaction is the work that has to be done to transfer money from one bank account to the other. It's atomic, because the money has to be deleted from account number one and has to be added to account number two in an atomic way. It's consistent because we don't want to loose or create any money (the total sum of money aften and before the transfer has to be the same). It's isolated because others should not see an intermediate state when the money has left account number one and is not on the second account yet. Last, it's durable because we want to keep the committed state forever (on a database restart, the money should not be back on the old account).&lt;/span&gt;&lt;/p&gt; &lt;p&gt; &lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Arial;font-size:85%;color:#000080;"&gt;&lt;strong&gt;SQL Server 2000 transaction isolation modes&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;In my definition of transactions, I mentioned the isolation property. The fact that transactions can't see anything from each other is simply an overstatement (or maybe it can even be called overengineering) in a lot of scenarios. Basically, there is one big tradeoff to be made: the level of concurrency versus the level of isolation. The higher the throughput you want to reach, the lower the level of isolation should be. Why is this? In one word, &lt;strong&gt;locking&lt;/strong&gt;. In order to make sure others can't perform certain operations on certain objects (I'm keeping this vague intentionally for the moment) you should get a certain lock on these certain objects. Examples are shared locks and exclusive locks in database technology.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;In SQL Server, a shared lock is acquired when data is read. More than one party can get a shared lock on the data, but nobody can get an exclusive lock on the data while there's still a shared lock on it. An exclusive lock is the result of a data modification (e.g. insert, update, delete). What's in a name? An exclusive lock is granted exclusively to one party (one process). Other parties can't get any type of lock on the data while there is such an exclusive lock on it. When the transaction completes, the lock can be released.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;One other thing before we jump into transaction isolation modes. The SQL Server database engine contains a &lt;strong&gt;transaction manager &lt;/strong&gt;which is responsible for everything around transactions, including cross-db transactions, distributed transactions, the support of savepoints, nested transactions, isolation level support, etc. A last concept you should have in mind is the concept of &lt;strong&gt;write-ahead logging&lt;/strong&gt;. Simply stated, write-ahead logging ensures that rolling back work in process and rolling forward committed work to be written to the physical data pages is always possible. The idea is that the transaction log is populated with the changes that a transaction has made before the transaction is acknowledges as being committed. The system can't simply continue until the transaction's work has been logged to the transaction log (that is, synchronously).&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Now back to the isolation modes. SQL Server 2000 has four different lock modi, as I'll explain now.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Arial;font-size:85%;color:#008000;"&gt;&lt;strong&gt;Uncommitted read&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;The weakest transaction isolation level is called uncommitted read. This means a transaction can read any data that's currently living on a data page, being committed or not. In fact, there is no isolation at all. There are simply no locks whatsoever when running in this mode, even no shared locks when reading data. So, you don't issue locks that can affect others and you don't have to wait for locks yourself either. Although this behavior affects concurrency positively, it's not the desired behavior for e.g. the financial application (money can get lost or can be created, because transactions can read intermediate states of other transactions, breaking the isolation). In data analysis scenarios this can be useful nevertheless.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Arial;font-size:85%;color:#008000;"&gt;&lt;strong&gt;Committed read&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;This is the default level. Data which has been changed can't ever be read by another transaction when it's not yet committed. During the data change (before the commit) an exclusive lock is held on the data. Other transactions have to wait for this lock to be released (and to acquire a shared lock) in order to continue. Also, data that is being read needs to hold a shared lock, because this blocks others from changing that data till the lock is released. However, shared locks can be released before the transaction is committed, when the read of the data has completed. This introduces the concept of &lt;em&gt;&lt;strong&gt;non-repeatable reads&lt;/strong&gt;&lt;/em&gt;. Basically this means that a transaction that is reading the same data more than once during the transaction can see different data on every read (because the shared lock doesn't need to be held in between two reads of the same data). Another concept is that of &lt;em&gt;&lt;strong&gt;phantoms&lt;/strong&gt;&lt;/em&gt;, which are new rows that appear in a table (or view) during a transaction. So, when you issue the same query more than once, new rows may have slipped in.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Arial;font-size:85%;color:#008000;"&gt;&lt;strong&gt;Repeatable read&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;As the name already tells us, this level ensures no non-repeatable reads can occur. The idea is that a shared lock is held till the transaction comes to an end, which negatively affects the overall performance because of possible lock contention (data which you are locking by a shared lock during a long transaction can't be modified by another transactions/user for the duration of your transaction; so it's key to reduce the length of transactions as much as you can). Therefore you can issue the same query multiple times in the context of the same transaction without having to worry about possible changes to the data you retrieved. However, &lt;em&gt;&lt;strong&gt;phantoms&lt;/strong&gt;&lt;/em&gt; still can occur.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Arial;font-size:85%;color:#008000;"&gt;&lt;strong&gt;Serializable&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;The summum of transaction isolation is called serializable. Basically serializable means that the result of running more than one serializable transaction concurrently is the same as running those transactions in a serialized fashion, one at a time. Next to the properties of repeatable read, phantoms can't occur too. This is done by locking on a higher level than the row/record level, e.g. the table level. The reason for this approach is the fact that we need to make sure no new rows can be added to the result sets we're using for the duration of our transaction. Assume you're querying a table for all registered members born between 1983 and 1985. If you do query this data for a second time in a serialized transaction, you don't want any phantom row to slip in. To accomplish this, SQL Server will acquire a &lt;em&gt;key-range lock&lt;/em&gt; on the data(range) so that's impossible for another transaction to add rows to this data set until the lock is released. There are nine subtypes of key-range locks in SQL Server 2000, more info can be found in the Books Online.&lt;/span&gt;&lt;/p&gt; &lt;p&gt; &lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Arial;font-size:85%;color:#000080;"&gt;&lt;strong&gt;How to set the transaction isolation level?&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Of course, that's the last thing you should know in order to start playing around with transaction isolation levels. To set the isolation level, use the &lt;strong&gt;SET TRANSACTION ISOLATION LEVEL&lt;/strong&gt; T-SQL statement. You can specify SERIALIZABLE, READ COMMITTED, REPEATABLE READ and READ UNCOMMITTED. More information can be found on &lt;a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_set-set_74bw.asp"&gt;MSDN&lt;/a&gt;.&lt;/span&gt;&lt;/p&gt; &lt;p&gt; &lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Arial;font-size:85%;color:#000080;"&gt;&lt;strong&gt;What about SQL Server 2005?&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;The answer is simple: there are a couple of new modi concerning transaction isolation levels, called &lt;strong&gt;snapshot isolation&lt;/strong&gt;. I won't cover this myself, but rather I want to point to an extract of the book "A First Look at SQL Server 2005 for Developers" which is available on &lt;a href="http://www.informit.com/articles/article.asp?p=327394&amp;seqNum=2&amp;amp;rl=1"&gt;http://www.informit.com/articles/article.asp?p=327394&amp;seqNum=2&amp;amp;rl=1&lt;/a&gt;.&lt;/span&gt;&lt;/p&gt;  &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-2989851836788232674?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://community.bartdesmet.net/blogs/bart/archive/2005/07/25/3077.aspx' title='transaction isolation levels'/><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/2989851836788232674/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=2989851836788232674' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/2989851836788232674'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/2989851836788232674'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2007/02/transaction-isolation-levels.html' title='transaction isolation levels'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-7921932920138012483</id><published>2007-01-26T09:05:00.000-05:00</published><updated>2007-01-26T09:15:06.408-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQL2000'/><title type='text'>Page records in SQL server</title><content type='html'>http://databases.aspfaq.com/database/how-do-i-page-through-a-recordset.html - &lt;span style="color: rgb(255, 102, 0);"&gt;How do I page through a recordset?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;http://databases.aspfaq.com/database/how-do-i-handle-alphabetic-paging.html ----&lt;span style="color: rgb(255, 102, 0);"&gt; How do I handle alphabetic paging?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a target="_blank" rel="nofollow" href="http://msdn2.microsoft.com/en-us/library/ms979197.aspx"&gt;http://msdn2.microsoft.com/en-us/library/ms979197.aspx&lt;/a&gt; --- &lt;span style="color: rgb(255, 0, 0);"&gt;Microsoft Solution&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;http://www.sqlteam.com/item.asp?ItemID=26455  - &lt;span style="color: rgb(204, 0, 0);"&gt;Server Side Paging using SQL Server 2005&lt;/span&gt;&lt;br /&gt;=========================================&lt;br /&gt;&lt;a target="_blank" rel="nofollow" href="http://www.aspfaq.com/show.asp?id=2120"&gt;http://www.aspfaq.com/show.asp?id=2120&lt;/a&gt;. --- &lt;span style="color: rgb(255, 0, 0);"&gt;Good site on SQL and this link explains SQL paging&lt;/span&gt;&lt;br /&gt;========================================&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;SQL 2005 books online ::&lt;/span&gt; http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;SQL 2000 books online:::: &lt;/span&gt;http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-7921932920138012483?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/7921932920138012483/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=7921932920138012483' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/7921932920138012483'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/7921932920138012483'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2007/01/page-records-in-sql-server.html' title='Page records in SQL server'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-7657019132273762267</id><published>2007-01-21T20:02:00.000-05:00</published><updated>2007-01-21T20:04:49.857-05:00</updated><title type='text'>Error When Installing Visual Studio 2005 SP1: "The installation source for this product is not available.</title><content type='html'>&lt;p&gt;Some Googling turned up a fix for a very common error message when installing SP1 - “Error 1718. File FileName was rejected by digital signature policy” - but it took a bit more searching before I found &lt;a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=245822"&gt;this bug report&lt;/a&gt; in which user rlasker provided the following helpful comment:&lt;/p&gt; &lt;blockquote dir="ltr" style="margin-right: 0px;"&gt; &lt;p&gt; I had this issue. When I looked in the event log I found this:&lt;/p&gt; &lt;p&gt;Event Type:    Error&lt;br /&gt;Event Source:    MsiInstaller&lt;br /&gt;Event Category:    None&lt;br /&gt;Event ID:    1008&lt;br /&gt;Date:        12/18/2006&lt;br /&gt;Time:        12:18:31 PM&lt;/p&gt; &lt;p&gt;Description:&lt;br /&gt;The installation of C:\DOCUME~1\...\LOCALS~1\Temp\ZNWA0\VS80sp1-KB926601-X86-ENU.msp is not permitted due to an error in software restriction policy processing. The object cannot be trusted.&lt;/p&gt; &lt;p&gt;I followed the instructions at this link:&lt;br /&gt;&lt;a href="http://support.microsoft.com/default.aspx/kb/925336"&gt;http://support.microsoft.com/default.aspx/kb/925336&lt;/a&gt;&lt;/p&gt; &lt;p&gt;And it no longer gave me the error descibed above. &lt;/p&gt;&lt;/blockquote&gt; &lt;p dir="ltr"&gt;Looking in my Event Log I found the same details and dutifully applied the workaround described at the KB (&lt;a href="http://support.microsoft.com/default.aspx/kb/925336"&gt;http://support.microsoft.com/default.aspx/kb/925336&lt;/a&gt;). These steps remedied the problem, and after rebooting I was able to successfully install SP1. Hopefully this post makes it to the first page of Google's results so future developers running into the same problem who are Googling the error message can more quickly find a fix.&lt;/p&gt; &lt;p dir="ltr"&gt;For more VS 2005 SP1 info, see:&lt;/p&gt; &lt;ul dir="ltr"&gt;&lt;li&gt; &lt;div&gt;&lt;a href="http://weblogs.asp.net/scottgu/archive/2006/12/15/visual-studio-2005-service-pack-1-sp1-released.aspx"&gt;Visual Studio Service Pack 1 Released&lt;/a&gt;&lt;/div&gt;&lt;/li&gt;&lt;li&gt; &lt;div&gt;&lt;a href="http://weblogs.asp.net/scottgu/archive/2007/01/01/a-few-vs-2005-sp1-links-and-information-nuggets.aspx"&gt;A Few VS 2005 SP1 Links and Information Nuggets&lt;/a&gt;&lt;/div&gt;&lt;/li&gt;&lt;li&gt; &lt;div&gt;&lt;a href="http://blogs.msdn.com/heaths/archive/2006/12/29/the-visual-studio-2005-service-pack-1-installation-experience.aspx"&gt;The Visual Studio 2005 Service Pack 1 Installation Experience&lt;/a&gt;&lt;/div&gt;&lt;/li&gt;&lt;li&gt; &lt;div&gt;&lt;a href="http://msdn.microsoft.com/vstudio/support/vs2005sp1/default.aspx"&gt;Visual Studio Service Pack 1&lt;/a&gt;&lt;/div&gt;&lt;/li&gt;&lt;li&gt; &lt;div&gt;&lt;a href="http://support.microsoft.com/kb/928957/"&gt;Visual Studio Service Pack 1 Release Notes&lt;/a&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-7657019132273762267?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/7657019132273762267/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=7657019132273762267' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/7657019132273762267'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/7657019132273762267'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2007/01/error-when-installing-visual-studio.html' title='Error When Installing Visual Studio 2005 SP1: &quot;The installation source for this product is not available.'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-6798022115693083845</id><published>2007-01-21T19:49:00.000-05:00</published><updated>2007-01-21T19:49:21.036-05:00</updated><title type='text'>Handling Errors in an ASP.NET Web Application</title><content type='html'>&lt;ul&gt;&lt;li&gt;Using custom, human-friendly error pages (avoid the &lt;a href="http://en.wikipedia.org/wiki/Yellow_Screen_of_Death"&gt;Yellow Screen of Death&lt;/a&gt;!)&lt;/li&gt;&lt;li&gt;Techniques for automatically logging unhandled exceptions&lt;/li&gt;&lt;li&gt;Ways to automatically notify developers in the face of an unhandled exception&lt;/li&gt;&lt;li&gt;How to handle exceptions that arise from the depths of ASP.NET 2.0's data source controls. That is, we'll see how to handle exceptions that occur when you are working with data in an ASP.NET 2.0 page using the SqlDataSource control and a GridView and an exception is raised from the database layer.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;If you can't make the talk, you can download the PowerPoint slides and code demos &lt;a href="http://datawebcontrols.com/classes/Errors.zip"&gt;here&lt;/a&gt;. Hope to see you tomorrow!&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-6798022115693083845?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://scottonwriting.net/sowblog/posts/10751.aspx' title='Handling Errors in an ASP.NET Web Application'/><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/6798022115693083845/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=6798022115693083845' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/6798022115693083845'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/6798022115693083845'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2007/01/handling-errors-in-aspnet-web.html' title='Handling Errors in an ASP.NET Web Application'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4971377397859266634.post-4216485171605541143</id><published>2007-01-19T12:23:00.000-05:00</published><updated>2007-04-16T16:27:42.039-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQL2000'/><title type='text'>Data Driven Query Task in DTS for updating data from Excel into SQL Server table</title><content type='html'>&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Arial;font-size:85%;color:navy;"&gt;&lt;span style="font-size: 10pt; color: navy; font-family: Arial;"&gt;This is a very common issue we face.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Arial;font-size:85%;color:navy;"&gt;&lt;span style="font-size: 10pt; color: navy; font-family: Arial;"&gt;There is a Excel sheet with data that needs to be imported into SQL Server table. The SQL Server table has unique key/primary key constraints on a key column (e.g. InspectorID). However the Excel spreadsheet can contain duplicates since this either being generated manually or coming from a different data source (typically a data warehouse). To be able to create a DTS script that uploads data from the Excel spreadsheet into Inspector table :&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Arial;font-size:85%;color:navy;"&gt;&lt;span style="font-size: 10pt; color: navy; font-family: Arial;"&gt;I divided the Inspector table upload process into 2 steps. In the first step I inserted all the distinct InspectorID’s from Excel spreadsheet into the Inspector Table using the &lt;span style="font-weight: bold;"&gt;TransformData Task&lt;/span&gt;  step in DTS, and for other columns that did not accept nulls, I used default values for these fields in the insert statement.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-family:Arial;font-size:85%;color:navy;"&gt;&lt;span style="font-size: 10pt; color: navy; font-family: Arial;"&gt;After this I used a  &lt;span style="font-weight: bold;"&gt;Data driven query Task&lt;/span&gt; to update the remaining fields of the Inspector table from  the spreadsheet. Working with this task was quite tricky, since at first glance  it would appear as if you are updating the Inspector table with the fields from the Inspector table itself. However, once you create a one-one mapping between the  fields in the Excel spreadsheet and the Inspector table using the &lt;span style="font-weight: bold;"&gt;ActiveX Script&lt;/span&gt;   in &lt;span style="font-weight: bold;"&gt;Transformations &lt;/span&gt;tab and set the query type to DTSTransformstat_UpdateQuery instead of  DTSTransformstat_InsertQuery, it automatically behind the scenes maps the source  (Excel) fields to the destination (Inspector table) fields.&lt;/span&gt;&lt;/span&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-family:Arial;font-size:85%;color:navy;"&gt;&lt;span style="font-size: 10pt; color: navy; font-family: Arial;"&gt; FYI, the various options available in the Transformations tab include: ActiveX Script, Copy Column, DateTime String, Lowercase String etc..&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Arial;font-size:85%;color:navy;"&gt;&lt;span style="font-size: 10pt; color: navy; font-family: Arial;"&gt;First in the &lt;span style="font-weight: bold;"&gt;Source &lt;/span&gt;you need to select the Connection1 (Excel) and then choose the Excel Spreadsheet from where the data is retrieved.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Arial;font-size:85%;color:navy;"&gt;&lt;span style="font-size: 10pt; color: navy; font-family: Arial;"&gt;Second in the &lt;span style="font-weight: bold;"&gt;Bindings &lt;/span&gt;tab select the Inspector table from Connection2 ( SQL Server connection)&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Arial;font-size:85%;color:navy;"&gt;&lt;span style="font-size: 10pt; color: navy; font-family: Arial;"&gt;Now if the column in the Excel Spreadsheet does not Map exactly with the column in Inspector table, then you can make use of the &lt;span style="font-weight: bold;"&gt;Lookups &lt;/span&gt;tab in either the Transform Data Task or the Data Driven Query Task.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Arial;font-size:85%;color:navy;"&gt;&lt;span style="font-size: 10pt; color: navy; font-family: Arial;"&gt;Thus you can create a lookup query such as : &lt;span style="color: rgb(255, 0, 0);"&gt;select InspectorTypeID from InspectorType where Type = ?&lt;/span&gt;. If this Lookup was named TypeLookup.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Arial;font-size:85%;color:navy;"&gt;&lt;span style="font-size: 10pt; color: navy; font-family: Arial;"&gt;Then you will need to modify the ActiveX Script in Transformations tab as follows:&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family: arial;"&gt;Function Main()&lt;br /&gt;    DTSDestination("InspectorID") = DTSSource("ID")&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: arial;"&gt;    DTSDestination("InspectorName") = DTSSource("Name")&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    DTSDestination("InspectorTypeID") = DTSLookups("TypeLookup").Execute(DTSSource("InspectorType"))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    Main = DTSTransformstat_UpdateQuery&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;End Function&lt;br /&gt;&lt;br /&gt;If it is a TransformData Task then the Function Main should be set to the value : &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family: arial;"&gt;DTSTransformStat_OK&lt;br /&gt;&lt;br /&gt;Then in the Queries Tab, select Update query and use the following query to update Inspector table:&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;update Inspector&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;set InspectorName = ?, InspectorType = ?&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;where InspectorID = ?&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;p class="MsoNormal"&gt;&lt;img src="file:///C:/DOCUME%7E1/rgupta/LOCALS%7E1/Temp/moz-screenshot.jpg" alt="" /&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-family:Arial;font-size:85%;color:navy;"&gt;&lt;span style="font-size: 10pt; color: navy; font-family: Arial;"&gt;Then click on Parse/Show Parameters then Map Parameter1 to InspectorName, Parameter2 to InspectorType and Parameter3 to InspectorID.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Arial;font-size:85%;color:navy;"&gt;&lt;span style="font-size: 10pt; color: navy; font-family: Arial;"&gt;Note that the dropdown for Parameters displays the columns from the Inspector table and not from the Excel spreadsheet. Thus you may wonder how would we get the values from the Excel spreadsheet to update the Inspector table. The trick is that since we have one-one mapping between the columns in the Excel spreadsheet and the Inspector table as we defined in the &lt;span style="font-weight: bold;"&gt;ActiveX Script&lt;/span&gt; in the &lt;span style="font-weight: bold;"&gt;Transformations &lt;/span&gt;tab, thus we get the values from the excel spreadsheet behind the scenes.&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:Arial;font-size:85%;color:navy;"&gt;&lt;span style="font-size: 10pt; color: navy; font-family: Arial;"&gt;Thus this task updates  the InspectorName and InspectorType number fields from the Excel spread sheet to  Inspector table for all the unique/distinct InspectorID’s that were inserted in the previous  “Transform Data Task” step.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4971377397859266634-4216485171605541143?l=rbgupta.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rbgupta.blogspot.com/feeds/4216485171605541143/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4971377397859266634&amp;postID=4216485171605541143' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/4216485171605541143'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4971377397859266634/posts/default/4216485171605541143'/><link rel='alternate' type='text/html' href='http://rbgupta.blogspot.com/2007/01/data-driven-query-task-in-dts-for.html' title='Data Driven Query Task in DTS for updating data from Excel into SQL Server table'/><author><name>Rohit Gupta</name><uri>http://www.blogger.com/profile/08950669136315735108</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry></feed>
