<?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>UH.LEE.KA &#187; SQL Server 2005</title>
	<atom:link href="http://www.uhleeka.com/blog/tag/sql-server-2005/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.uhleeka.com/blog</link>
	<description>If you think nobody cares about you, try missing a few car payments.</description>
	<lastBuildDate>Wed, 25 Aug 2010 01:35:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Sql Server 2005 &#8220;Login name&#8221; is blank after restoring from backup</title>
		<link>http://www.uhleeka.com/blog/2009/05/sql-server-2005-login-name-is-blank-after-restoring-from-backup/</link>
		<comments>http://www.uhleeka.com/blog/2009/05/sql-server-2005-login-name-is-blank-after-restoring-from-backup/#comments</comments>
		<pubDate>Fri, 29 May 2009 03:14:36 +0000</pubDate>
		<dc:creator>uhleeka</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server 2005]]></category>

		<guid isPermaLink="false">http://www.uhleeka.com/blog/?p=268</guid>
		<description><![CDATA[After restoring a database from a remote server backup, the &#8220;Login name&#8221; is often disassociated. The Solution USE [database_name]; GO EXEC sp_change_users_login 'Auto_Fix', 'Username'; GO SQL should respond with the following: The row for user 'Username' will be fixed by updating its login link to a login already in existence. The number of orphaned users [...]]]></description>
			<content:encoded><![CDATA[<div style="float:left;width:93px;height:93px;margin:8px 8px 0px 0px;border:solid 1px #600;background-color:#fff;background-repeat:no-repeat;background-position:15px center;background-image:url('http://www.uhleeka.com/blog/wp-content/uploads/2009/02/sql08-3.png');"></div>
<p>After restoring a database from a remote server backup, the &#8220;Login name&#8221; is often disassociated.<span id="more-268"></span></p>
<h4 style="clear:both;">The Solution</h4>

<div class="uhleeka_codebox"><div class="uhleeka_codebox_in"><pre>USE [database_name];
GO
EXEC sp_change_users_login 'Auto_Fix', 'Username';
GO</pre></div></div>

<p>SQL should respond with the following:</p>

<div class="uhleeka_codebox"><div class="uhleeka_codebox_in"><pre>The row for user 'Username' will be fixed by updating its login link to a login
already in existence.
The number of orphaned users fixed by updating users was 1.
The number of orphaned users fixed by adding new logins and then updating users was 0.</pre></div></div>

<p>For more info:<br />
<a href="http://msdn.microsoft.com/en-us/library/ms174378.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/ms174378.aspx</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.uhleeka.com/blog/2009/05/sql-server-2005-login-name-is-blank-after-restoring-from-backup/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Preserving Whitespace FOR OPENXML</title>
		<link>http://www.uhleeka.com/blog/2009/02/preserving-whitespace-for-openxml/</link>
		<comments>http://www.uhleeka.com/blog/2009/02/preserving-whitespace-for-openxml/#comments</comments>
		<pubDate>Thu, 12 Feb 2009 21:34:03 +0000</pubDate>
		<dc:creator>uhleeka</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[Xml]]></category>

		<guid isPermaLink="false">http://www.uhleeka.com/blog/?p=239</guid>
		<description><![CDATA[Using Microsoft SQL Server 2005, when you read xml data using FOR OPENXML, whitespace characters are replaced with a single space. After digging through the internet for half an hour, I found a couple options. The Problem If you take the following Xml, &#60;Root&#62; &#160; &#160; &#60;Node value=&#34;Line1&#38;#xA;Line2&#38;#xA;Line3&#38;#xA;&#34; /&#62; &#60;/Root&#62; and run it through a [...]]]></description>
			<content:encoded><![CDATA[<div style="float:left;width:93px;height:93px;margin:8px 8px 0px 0px;border:solid 1px #600;background-color:#fff;background-repeat:no-repeat;background-position:15px center;background-image:url('http://www.uhleeka.com/blog/wp-content/uploads/2009/02/sql08-3.png');"></div>
<p>Using Microsoft SQL Server 2005, when you read xml data using FOR OPENXML, whitespace characters are replaced with a single space.  After digging through the internet for half an hour, I found a couple options.  <span id="more-239"></span></p>
<h4 style="clear:both;">The Problem</h4>
<p>If you take the following Xml,</p>

<div class="uhleeka_codebox"><div class="uhleeka_codebox_in"><pre>&lt;Root&gt;
&nbsp; &nbsp; &lt;Node value=&quot;Line1&amp;#xA;Line2&amp;#xA;Line3&amp;#xA;&quot; /&gt;
&lt;/Root&gt;</pre></div></div>

<p>and run it through a FOR OPENXML query</p>

<div class="uhleeka_codebox"><div class="uhleeka_codebox_in"><pre>DECLARE 
&nbsp; &nbsp; @strXML nvarchar(MAX), 
&nbsp; &nbsp; @hDoc int 

SET @strXML = N'&lt;Root&gt;&lt;Node value=&quot;Line1&amp;#xA;Line2&amp;#xA;Line3&amp;#xA;&quot; /&gt;&lt;/Root&gt;'

exec sp_xml_preparedocument @hDoc output, @strXML

SELECT Node FROM OPENXML(@hDoc, '/Root') WITH (Node xml 'Node')

exec sp_xml_removedocument @hDoc</pre></div></div>

<p>SQL strips/replaces the whitespace characters, leaving you with the following:</p>

<div class="uhleeka_codebox"><div class="uhleeka_codebox_in"><pre>&lt;Node value=&quot;Line1 Line2 Line3 &quot; /&gt;</pre></div></div>

<h4>The Options</h4>
<p>One option is to use the nodes() functionality.  It is a complete alternative to using FOR OPENXML, introduced in SQL 2005.  A couple of things deterred me from using this approach.  Although performance is not going to be an issue for me, there seemed to be a number of related complaints.  Further, I didn&#8217;t want to rewrite a significant portion of my codebase if it wasn&#8217;t necessary.</p>
<p>Instead, i simply pulled my data out of an xml attribute (i found no way to prevent FOR OPENXML from rewriting attribute whitepace) and stuck it in a CDATA.</p>

<div class="uhleeka_codebox"><div class="uhleeka_codebox_in"><pre>SET @strXML = N'&lt;Root&gt;&lt;Node&gt;&lt;![CDATA[
Line1
Line2
Line3
]]&gt;&lt;/Node&gt;&lt;/Root&gt;'</pre></div></div>

<p>Results:</p>

<div class="uhleeka_codebox"><div class="uhleeka_codebox_in"><pre>&lt;Node&gt;
Line1
Line2
Line3
&lt;/Node&gt;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.uhleeka.com/blog/2009/02/preserving-whitespace-for-openxml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
