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

<channel>
	<title>YSW Consulting Blog</title>
	<atom:link href="http://yswconsulting.com/blog1/index.php/feed/" rel="self" type="application/rss+xml" />
	<link>http://yswconsulting.com/blog1</link>
	<description>Yvette Whitaker&#039;s VB Solutions</description>
	<lastBuildDate>Mon, 15 Feb 2010 21:39:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Encrypting Data With Symmetric Keys in SQL Server</title>
		<link>http://yswconsulting.com/blog1/2010/02/14/encrypting-data-with-symmetric-keys-in-sql-server/</link>
		<comments>http://yswconsulting.com/blog1/2010/02/14/encrypting-data-with-symmetric-keys-in-sql-server/#comments</comments>
		<pubDate>Sun, 14 Feb 2010 21:51:35 +0000</pubDate>
		<dc:creator>ywhitaker</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://yswconsulting.com/blog1/?p=39</guid>
		<description><![CDATA[SQL Server 2005 introduced native database encryption capabilities. This, simply put, makes it easy for you to protect sensitive data from outside attacks. This article looks at how to set up and use encryption on a simple database table.
First, create a table for testing purposes in your existing database:
CREATE TABLE [dbo].[CreditCards] (CardId INT PRIMARY KEY [...]]]></description>
			<content:encoded><![CDATA[<p>SQL Server 2005 introduced native database encryption capabilities. This, simply put, makes it easy for you to protect sensitive data from outside attacks. This article looks at how to set up and use encryption on a simple database table.</p>
<p>First, create a table for testing purposes in your existing database:</p>
<p><span style="color: #3366ff;">CREATE TABLE [dbo].[CreditCards] (CardId INT PRIMARY KEY , CardNumber varbinary(256) )<br />
GO</span></p>
<p>This creates a simple table with two columns.</p>
<p>Now, you will create a Symmetric Key that uses a password for authentication. Another option is to use a certificate, but that won&#8217;t be covered here.</p>
<p><span style="color: #3366ff;">CREATE SYMMETRIC KEY [PasswordProtectedKey] <br />
WITH ALGORITHM = TRIPLE_DES <br />
ENCRYPTION BY PASSWORD</span> = <span style="color: #ff0000;">&#8216;12345&#8242;</span><br />
<span style="color: #3366ff;">GO</span></p>
<p>You can now enter some test data into the CreditCard table. Note that you must first open the key.</p>
<p><span style="color: #3366ff;">OPEN SYMMETRIC KEY <span style="color: #000000;">[PasswordProtectedKey]</span> <span style="color: #000000;">DECRYPTION</span> BY <span style="color: #000000;">PASSWORD</span> =</span> <span style="color: #ff0000;">&#8216;12345&#8242;</span></p>
<p><span style="color: #3366ff;">GO</span></p>
<p><span style="color: #339966;">&#8211; Insert some data into your test table</span><br />
<span style="color: #3366ff;">DECLARE <span style="color: #000000;">@KeyGuid</span> AS UNIQUEIDENTIFIER </span><br />
<span style="color: #3366ff;">SET <span style="color: #000000;">@KeyGuid </span>= <span style="color: #000000;">key_guid(</span><span style="color: #ff0000;">&#8216;PasswordProtectedKey&#8217;<span style="color: #000000;">)</span></span></span></p>
<p><span style="color: #3366ff;">INSERT INTO <span style="color: #000000;">[CreditCards]</span> VALUES ( <span style="color: #000000;">1, encryptbykey(</span> <span style="color: #000000;">@KeyGuid</span>, </span><span style="color: #000000;">N</span><span style="color: #ff0000;">&#8216;1111-0000-0000-0000&#8242;</span>))<br />
<span style="color: #3366ff;">INSERT INTO</span> <span style="color: #000000;">[CreditCards]</span> <span style="color: #3366ff;">VALUES ( <span style="color: #000000;">1, encryptbykey(</span> </span>@KeyGuid, <span style="color: #ff0000;">N&#8217;2222-0000-0000-0000&#8242;</span>))<br />
<span style="color: #3366ff;">CLOSE SYMMETRIC KEY</span> [PasswordProtectedKey]<br />
<span style="color: #3366ff;">GO</span></p>
<p>Now you can try retrieving data from your table. First, try running an ordinary SELECT statement and note that the returned data is encrypted and unuseable. In order to return unencrypted data, you must use the key:</p>
<p><span style="color: #3366ff;">OPEN SYMMETRIC KEY</span> [PasswordProtectedKey] DECRYPTION <span style="color: #3366ff;">BY</span> PASSWORD = <span style="color: #ff0000;">&#8216;12345&#8242;<br />
</span><span style="color: #3366ff;">GO</span></p>
<p><span style="color: #3366ff;">SELECT</span> CardId, <span style="color: #ff00ff;">convert</span>( <span style="color: #3366ff;">NVARCHAR</span>(100), decryptbykey( CardNumber )) <span style="color: #3366ff;">AS</span> <span style="color: #ff0000;">&#8216;Card Number&#8217;</span><br />
<span style="color: #3366ff;">FROM</span> [dbo].[CreditCards]<br />
<span style="color: #3366ff;">GO</span></p>
<p>And what if you want to find a specific credit card number?</p>
<p><span style="color: #3366ff;">OPEN SYMMETRIC KEY </span>[PasswordProtectedKey] DECRYPTION <span style="color: #3366ff;">BY</span> PASSWORD =<span style="color: #ff0000;"> &#8216;12345&#8242;</span><br />
<span style="color: #3366ff;">GO</span></p>
<p><span style="color: #3366ff;">SELECT </span>CardId, <span style="color: #ff00ff;">convert</span>( <span style="color: #3366ff;">NVARCHAR</span>(100), decryptbykey( CardNumber )) <span style="color: #3366ff;">AS</span> &#8216;Card Number&#8217;<br />
<span style="color: #3366ff;">FROM</span> [dbo].[CreditCards]<br />
<span style="color: #3366ff;">WHERE</span> convert( <span style="color: #3366ff;">NVARCHAR</span>(100), decryptbykey( CardNumber )) =<span style="color: #ff0000;"> &#8216;2222-0000-0000-0000&#8242; </span></p>
<p><span style="color: #3366ff;">GO</span></p>
<p>If you need to change the password:</p>
<p><span style="color: #3366ff;">OPEN SYMMETRIC KEY </span>[PasswordProtectedKey] DECRYPTION <span style="color: #3366ff;">BY</span> PASSWORD = <span style="color: #ff0000;">&#8216;12345&#8242;</span></p>
<p>GO</p>
<p><span style="color: #3366ff;">ALTER SYMMETRIC KEY </span>PasswordProtectedKey<br />
<span style="color: #3366ff;">ADD</span> ENCRYPTION <span style="color: #3366ff;">BY</span> PASSWORD =<span style="color: #ff0000;"> &#8216;67890&#8242;</span><br />
GO</p>
<p><span style="color: #3366ff;">ALTER SYMMETRIC KEY</span> PasswordProtectedKey<br />
<span style="color: #3366ff;">DROP</span> ENCRYPTION <span style="color: #3366ff;">BY</span> PASSWORD =<span style="color: #ff0000;">&#8216;12345&#8242;<br />
</span>GO</p>
<p>And to remove your key entirely:</p>
<p><span style="color: #3366ff;">CLOSE SYMMETRIC KEY</span> PasswordProtectedKey<br />
<span style="color: #3366ff;">DROP SYMMETRIC KEY</span> PasswordProtectedKey</p>
]]></content:encoded>
			<wfw:commentRss>http://yswconsulting.com/blog1/2010/02/14/encrypting-data-with-symmetric-keys-in-sql-server/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Entering A Value Into A SQL Server Identity Field</title>
		<link>http://yswconsulting.com/blog1/2010/02/04/entering-a-value-into-a-sql-server-identity-field/</link>
		<comments>http://yswconsulting.com/blog1/2010/02/04/entering-a-value-into-a-sql-server-identity-field/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 23:15:55 +0000</pubDate>
		<dc:creator>ywhitaker</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://yswconsulting.com/blog1/?p=22</guid>
		<description><![CDATA[Identity columns automatically assign a value for each new row inserted. Most of the time, you wouldn&#8217;t want to force a value in, but occasionally you may have special circumstances. If you need to insert your own value into an identity column, all you have to do is execute this statement in your stored procedure:
SET [...]]]></description>
			<content:encoded><![CDATA[<p>Identity columns automatically assign a value for each new row inserted. Most of the time, you wouldn&#8217;t want to force a value in, but occasionally you may have special circumstances. If you need to insert your own value into an identity column, all you have to do is execute this statement in your stored procedure:</p>
<p><span style="color: #0000ff;">SET IDENTITY_INSERT</span> YourTable <span style="color: #0000ff;">ON</span></p>
<p>Example:</p>
<div><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;"><span style="color: #0000ff;">SET IDENTITY_INSERT</span> <span style="color: #333333;">YourTable</span> <span style="color: #0000ff;">ON</span></span></span></div>
<div><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;"> </span></span></span></span></span></div>
<div><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;">INSERT </span></span><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;">INTO</span></span><span style="font-size: x-small;"> YourTable </span></span></span></span></div>
<div><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small;"> </span></span></span></span></div>
<div><span style="font-size: x-small; color: #808080;"><span style="font-size: x-small; color: #808080;">(</span></span><span style="font-size: x-small;">YourIdentityCol</span><span style="font-size: x-small; color: #808080;"><span style="font-size: x-small; color: #808080;">,</span></span><span style="font-size: x-small;"> SomeOtherCol</span><span style="font-size: x-small; color: #808080;"><span style="font-size: x-small; color: #808080;">)</span></span></div>
<p><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;">VALUES</span></span></p>
<div><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;"> </span></span><span style="font-size: x-small; color: #808080;"><span style="font-size: x-small; color: #808080;">(</span></span><span style="font-size: x-small;">3</span><span style="font-size: x-small; color: #808080;"><span style="font-size: x-small; color: #808080;">,</span></span><span style="font-size: x-small;"> &#8220;Other Info&#8221;</span><span style="font-size: x-small; color: #808080;"><span style="font-size: x-small; color: #808080;">)</span></span></div>
<div><span style="font-size: x-small; color: #808080;"><span style="font-size: x-small; color: #808080;"> </span></span></div>
<div><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;"> </span></span></span></span><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;">SET </span></span></span></span><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;">IDENTITY_INSERT</span></span><span style="font-size: x-small;"> YourTable </span><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;">OFF</span></span></span></span></div>
<div><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;"> </span></span></span></span></div>
<div><span style="color: #000000;">In this example you are inserting the value &#8220;3&#8243; into the Identity Column.</span></div>
<p>Note that you MUST turn off the IDENTITY_INSERT property at the end of your stored procedure. Only one table in a session can have the IDENTITY_INSERT property set to ON. If a table already has this property set to ON, and you issue a  SET IDENTITY_INSERT ON statement for another table, you&#8217;ll get an error message.</p>
<p>When using this statement in a stored procedure, make sure you place it after the <span style="color: #0000ff;">AS</span>, like this:</p>
<div><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;">CREATE </span></span></span></span><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;">PROCEDURE</span></span><span style="font-size: x-small;"> <span style="color: #888888;">[dbo]</span></span><span style="color: #888888;"><span style="font-size: x-small;"><span style="font-size: x-small;">.</span></span><span style="font-size: x-small;">[me_MyProcedure]</span></span></span></span></div>
<div><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small;">AS</span></span></span></div>
<div><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;"> </span></span><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;">SET IDENTITY_INSERT<span style="font-size: x-small;"> <span style="color: #888888;">DBO</span></span><span style="font-size: x-small; color: #808080;"><span style="font-size: x-small;"><span style="color: #888888;">.</span></span></span><span style="font-size: x-small;"><span style="color: #888888;">MyTable</span> </span><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;">ON</span></span></span></span></div>
<div><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small;"><span style="color: #0000ff;">INSERT</span>  </span><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;">INTO</span></span><span style="font-size: x-small;"> <span style="color: #888888;">MyTable</span></span></span></span></div>
<div><span style="color: #ff0000;">etc etc etc</span></div>
<p>Other things to note:</p>
<ul>
<li>If the value inserted is larger than the current identity value for the table, SQL Server automatically uses the new inserted value as the current identity value.</li>
<li>User must own the object, or be a member of the <strong>sysadmin</strong> fixed server role, or the <strong>db_owner</strong> and <strong>db_ddladmin</strong> fixed database roles.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://yswconsulting.com/blog1/2010/02/04/entering-a-value-into-a-sql-server-identity-field/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Finding Duplicate Records In A Database Table</title>
		<link>http://yswconsulting.com/blog1/2010/01/15/finding-duplicate-records-in-a-database-table/</link>
		<comments>http://yswconsulting.com/blog1/2010/01/15/finding-duplicate-records-in-a-database-table/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 16:30:02 +0000</pubDate>
		<dc:creator>ywhitaker</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://yswconsulting.com/blog1/?p=12</guid>
		<description><![CDATA[The other day, someone asked me if there was a simple way to figure out if a db table contains duplicate records. The answer is yes and the good news is that it&#8217;s very easy to do.
Let&#8217;s say you have an Employee table and want to find out if it contains any duplicate SSNs. This [...]]]></description>
			<content:encoded><![CDATA[<p>The other day, someone asked me if there was a simple way to figure out if a db table contains duplicate records. The answer is yes and the good news is that it&#8217;s very easy to do.</p>
<p>Let&#8217;s say you have an Employee table and want to find out if it contains any duplicate SSNs. This simple SQL statement will identify any records that share an SSN:</p>
<p><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;">SELECT SSN FROM Employee</span></span></span></span></p>
<p><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;">GROUP BY SSN</span></span></span></span></p>
<p><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;">HAVING <span style="color: #ff00ff;">count</span>(SSN) &gt; 1</span></span></span></span></p>
<p><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;"> </span></span></span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://yswconsulting.com/blog1/2010/01/15/finding-duplicate-records-in-a-database-table/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Windows 7: Error 2869</title>
		<link>http://yswconsulting.com/blog1/2009/12/04/error-2869-on-windows-7/</link>
		<comments>http://yswconsulting.com/blog1/2009/12/04/error-2869-on-windows-7/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 18:18:34 +0000</pubDate>
		<dc:creator>ywhitaker</dc:creator>
				<category><![CDATA[Visual Basic 2005]]></category>
		<category><![CDATA[Windows 7]]></category>

		<guid isPermaLink="false">http://yswconsulting.com/blog1/?p=3</guid>
		<description><![CDATA[Problem: Your installer works on Windows XP but suddenly starts giving you the following error when you run it on Windows 7 or Vista:
&#8220;The installer has encountered an unexpected error installing this package. This may indicate a problem with this package. The error code is 2869&#8243; 
If your installer contains a custom action, it could be causing the [...]]]></description>
			<content:encoded><![CDATA[<p>Problem: Your installer works on Windows XP but suddenly starts giving you the following error when you run it on Windows 7 or Vista:</p>
<p><em>&#8220;The installer has encountered an unexpected error installing this package. This may indicate a problem with this package. The error code is 2869&#8243;</em> </p>
<p>If your installer contains a custom action, it could be causing the error message. Starting with Windows Vista, it is necessary to set the <strong>NoImpersonate</strong> flag for custom actions that modify the system. This can be done with a simple script.</p>
<p>Create a script named NoImpersonate.js:</p>
<p>// This script performs a post-build fixup of an msi to change all deferred custom actions to NoImpersonate</p>
<p>// Constant values from Windows Installer</p>
<p>var msiOpenDatabaseModeTransact = 1;</p>
<p>var msiViewModifyInsert = 1</p>
<p>var msiViewModifyUpdate = 2</p>
<p>var msiViewModifyAssign = 3</p>
<p>var msiViewModifyReplace = 4</p>
<p>var msiViewModifyDelete = 6</p>
<p>var msidbCustomActionTypeInScript = 0&#215;00000400;</p>
<p>var msidbCustomActionTypeNoImpersonate = 0&#215;00000800</p>
<p>if (WScript.Arguments.Length != 1)</p>
<p>{</p>
<p>WScript.StdErr.WriteLine(WScript.ScriptName + &#8221; file&#8221;);</p>
<p>WScript.Quit(1);</p>
<p>}</p>
<p>var filespec = WScript.Arguments(0);</p>
<p>var installer = WScript.CreateObject(&#8220;WindowsInstaller.Installer&#8221;);</p>
<p>var database = installer.OpenDatabase(filespec, msiOpenDatabaseModeTransact);</p>
<p>var sql</p>
<p>var view</p>
<p>var record</p>
<p>try</p>
<p>{</p>
<p>sql = &#8220;SELECT `Action`, `Type`, `Source`, `Target` FROM `CustomAction`&#8221;;</p>
<p>view = database.OpenView(sql);</p>
<p>view.Execute();</p>
<p>record = view.Fetch();</p>
<p>while (record)</p>
<p>{</p>
<p>if (record.IntegerData(2) &amp; msidbCustomActionTypeInScript)</p>
<p>{</p>
<p>record.IntegerData(2) = record.IntegerData(2) | msidbCustomActionTypeNoImpersonate;</p>
<p>view.Modify(msiViewModifyReplace, record);</p>
<p>}</p>
<p>record = view.Fetch();</p>
<p>}</p>
<p>view.Close();</p>
<p>database.Commit();</p>
<p>}</p>
<p>catch(e)</p>
<p>{</p>
<p>WScript.StdErr.WriteLine(e);</p>
<p>WScript.Quit(1);</p>
<p>}</p>
<p>Save the script in the same directory as your Setup project. Next, enter the following in your Setup project&#8217;s Post Build event:</p>
<p>cscript.exe &#8220;$(ProjectDir)CustomAction_NoImpersonate.js&#8221; &#8220;$(BuiltOuputPath)&#8221;</p>
<p>Build the project and try running it again.</p>
<p>You can read more about this issue and also download a sample script at <a title="Aaron Stebner's Weblog" href="http://blogs.msdn.com/astebner/archive/2006/10/23/mailbag-how-to-set-the-noimpersonate-flag-for-a-custom-action-in-visual-studio-2005.aspx" target="_blank">Aaron Stebner&#8217;s Weblog. </a></p>
<p>For even more detail, look at Microsoft&#8217;s topic <a title="Custom ACtion In-Script Execution Options" href="http://msdn.microsoft.com/en-us/library/aa368069(VS.85).aspx" target="_blank">Custom Action In-Script Execution Options</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://yswconsulting.com/blog1/2009/12/04/error-2869-on-windows-7/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.342 seconds -->

