<?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>dbdesc - document your database! &#187; sqlserver</title>
	<atom:link href="http://www.dbdesc.com/blog/archives/category/sqlserver/feed" rel="self" type="application/rss+xml" />
	<link>http://www.dbdesc.com/blog</link>
	<description>document your database!</description>
	<lastBuildDate>Tue, 20 Apr 2010 14:54:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Login failed for user ‘sa’. 4 things to check</title>
		<link>http://www.dbdesc.com/blog/archives/login-failed-for-user-sa-4-things-to-check</link>
		<comments>http://www.dbdesc.com/blog/archives/login-failed-for-user-sa-4-things-to-check#comments</comments>
		<pubDate>Tue, 07 Jul 2009 09:42:14 +0000</pubDate>
		<dc:creator>JAG</dc:creator>
				<category><![CDATA[sqlserver]]></category>

		<guid isPermaLink="false">http://dbdesc.com/blog/archives/login-failed-for-user-sa-4-things-to-check</guid>
		<description><![CDATA[Last week a customer of one of my applications (not dbdesc nor dtsdoc), reported the following error when the app performed a special task: Login failed for user 'sa' &#160; .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } [...]]]></description>
			<content:encoded><![CDATA[<p>Last week a customer of one of my applications (not dbdesc nor dtsdoc), reported the following error when the app performed a special task:</p>
<pre class="csharpcode">Login failed for user 'sa'</pre>
<pre class="csharpcode">&nbsp;</pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>This app installs its own SQL Server instance with SQL Server authentication and it manages the users including the sa account. There&#8217;s no way to change the &#8216;<em>sa&#8217;</em> password from the application, so probably someone might have been <em>playing</em> with my instance.</p>
<p>I logged in to this server and connect to SQL Server using the <em>osql</em> tool using windows authentication:</p>
<pre class="csharpcode">osql -E -S .\MYAPP</pre>
<pre class="csharpcode">&nbsp;</pre>
<p>I then reset the sa password back to the original one:</p>
<pre class="csharpcode">1<span class="kwrd">&gt;</span> sp_password NULL, 'mypassword', 'sa'</pre>
<pre class="csharpcode">&nbsp;</pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>Unfortunately, this didn&#8217;t solve the problem. So the &#8216;<em>sa&#8217;</em> password was intact after all.</p>
<p>Next thing I checked was that <em>mixed-mode authentication </em>was indeed enabled. It was unlikely that someone had changed this but.</p>
<p>I checked the registry key: </p>
<pre class="csharpcode">HKLM\Software\Microsoft\Microsoft SQL Server\Instance Name\MSSQLServer\LoginMode</pre>
<pre class="csharpcode">&nbsp;</pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>It had <a href="http://support.microsoft.com/kb/285097">the correct value</a> 2 which means mixed-mode.</p>
<p>What else to check? Ah, maybe the &#8216;<em>sa&#8217; </em>login has been disabled. Let&#8217;s enable it again:</p>
<pre class="csharpcode"><span class="kwrd">ALTER</span> LOGIN sa ENABLE ;
<span class="kwrd">GO</span>
<span class="kwrd">ALTER</span> LOGIN sa <span class="kwrd">WITH</span> PASSWORD = <span class="str">'mypassword'</span>;
<span class="kwrd">GO</span></pre>
<pre class="csharpcode"><span class="kwrd"></span></pre>
<p><style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>No luck, still can&#8217;t log in using the <em>sa</em> user.</p>
<p>Here I started to be worried about this issue. I checked the system logs, nothing special there. Some errors reporting that &#8216;<em>sa&#8217; </em>was unable to connect to SQL Server and nothing else. I also checked the SQL Server errorlog file. Everything seemed normal.</p>
<p>I have to say that this company has no IT department per se, but a guy who regularly helps them with their domain, active directory, etc. This guy was on vacation and unreachable.</p>
<p>I had no other option that to ask my customer if they had made any changes to their server, hoping to get some clue about what was going on. And he confessed. They were making changes to<em> </em>the Windows security policy editor adding and removing permissions a few days ago. He didn&#8217;t know exactly what they did, only that they &#8220;touch&#8221; different things (ouch!!).</p>
<p>Anyway, not my problem. Fortunately this gave me the clue I was looking for. The &#8216;<em>sa&#8217;</em> user was being affected by a Windows policy setting. So I fixed it using this code:</p>
<pre class="csharpcode"><span class="kwrd">ALTER</span> LOGIN [sa] <span class="kwrd">WITH</span> PASSWORD=<span class="str">'mypassword'</span>, <strong>CHECK_POLICY=<span class="kwrd">OFF</span></strong>
<span class="kwrd">GO</span>
<span class="kwrd">ALTER</span> LOGIN [sa] ENABLE
GO</pre>
<pre class="csharpcode">&nbsp;</pre>
<p>Note the <em>CHECK_POLICY</em> parameter. It makes the login immune to domain setup changes.</p>
<p>In summary:</p>
<h2>4 things to check if you can&#8217;t log in to SQL Server using the sa account</h2>
<ol>
<li>Check the password and provide a new one if necessary
<pre class="csharpcode">sp_password <span class="kwrd">NULL</span>, <span class="str">'mypassword'</span>, <span class="str">'sa'</span></pre>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
</li>
<li>Check that mixed-mode authentication is enabled
<pre class="csharpcode">HKLM\Software\Microsoft\Microsoft SQL Server\InstanceName\MSSQLServer\LoginMode</pre>
<p>Should have the value 2. If not, change it and remember to restart the service. </p>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
</li>
<li>Enable the sa account
<pre class="csharpcode"><span class="kwrd">ALTER</span> LOGIN sa ENABLE</pre>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<pre></pre>
</li>
<li>Check that the sa account is not being affected by the domain security policy
<pre class="csharpcode"><span class="kwrd">ALTER</span> LOGIN [sa] <span class="kwrd">WITH</span> PASSWORD=<span class="str">'mypassword'</span>, CHECK_POLICY=<span class="kwrd">OFF</span></pre>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.dbdesc.com/blog/archives/login-failed-for-user-sa-4-things-to-check/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Documenting SQL Server 2008 RC0 databases</title>
		<link>http://www.dbdesc.com/blog/archives/documenting-sql-server-2008-rc0-databases</link>
		<comments>http://www.dbdesc.com/blog/archives/documenting-sql-server-2008-rc0-databases#comments</comments>
		<pubDate>Tue, 15 Jul 2008 04:52:21 +0000</pubDate>
		<dc:creator>JAG</dc:creator>
				<category><![CDATA[dbdesc]]></category>
		<category><![CDATA[sqlserver]]></category>

		<guid isPermaLink="false">http://dbdesc.com/blog/archives/documenting-sql-server-2008-rc0-databases</guid>
		<description><![CDATA[One of my customers asked me yesterday if dbdesc 3.0 supports SQL Server 2008 databases. The answer is yes, dbdesc works just fine with SQL Server 2008 RC0 and even documents the new data types. There is however a small issue&#8230; it won&#8217;t script tables. The current version of SMO does not support SQL Server [...]]]></description>
			<content:encoded><![CDATA[<p>One of my customers asked me yesterday if dbdesc 3.0 supports SQL Server 2008 databases. </p>
<p>The answer is yes, dbdesc works just fine with SQL Server 2008 RC0 and even documents the new data types. </p>
<p><img src="http://files.dbdesc.com/images/sql2008_new_datatypes.gif" alt="SQL Server 2008 new data types" /></p>
<p>There is however a small issue&#8230; it won&#8217;t script tables. The current version of SMO does not support SQL Server 2008 databases and even though there is a workaround using DMO, I prefer to wait until the RTM version.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dbdesc.com/blog/archives/documenting-sql-server-2008-rc0-databases/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Diagnose SQL Server 2005 SP2 install problems</title>
		<link>http://www.dbdesc.com/blog/archives/diagnose-sql-server-2005-sp2-install-problems</link>
		<comments>http://www.dbdesc.com/blog/archives/diagnose-sql-server-2005-sp2-install-problems#comments</comments>
		<pubDate>Fri, 28 Mar 2008 08:44:25 +0000</pubDate>
		<dc:creator>JAG</dc:creator>
				<category><![CDATA[sqlserver]]></category>

		<guid isPermaLink="false">http://dbdesc.com/blog/archives/diagnose-sql-server-2005-sp2-install-problems</guid>
		<description><![CDATA[I was checking the pending updates in one of my test VISTA machines and the SQL Server 2005 Service Pack 2 was still in the list. I tried to install it using Windows Update but it returned an error: Error code 2B22. The link Get Help didn’t bring any help as the error code was [...]]]></description>
			<content:encoded><![CDATA[<p>I was checking the pending updates in one of my test VISTA machines and the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=d07219b2-1e23-49c8-8f0c-63fa18f26d3a&#038;displaylang=en">SQL Server 2005 Service Pack 2</a> was still in the list. I tried to install it using Windows Update but it returned an error: Error code 2B22.<br />
<img src="http://www.dtsdoc.com/common_images/Windows_Update.png" alt="Windows Update Error code 2B22" /><br />
The link <em>Get Help</em> didn’t bring any help as the error code was not in the list. So I googled for it. Surprisingly I get very few results and most of them were the same Microsoft forum post republished by others sites. The post was simply someone asking for help and a couple of <em>‘me too’</em> responses.</p>
<p>Anyway, I needed more info about the problem so I looked for a log in my system. I’ve founded it in <em>C:\Program Files\Microsoft SQL Server\90\Setup Bootstrap\LOG\Hotfix</em></p>
<p>The file you want to look at is <em>Summary.txt</em> which holds the log of the last update. You may see other files like <em>Summary_0.txt, Summary_1.txt … Summary_N.txt</em>. Those contain information about past updates.<br />
<img src="http://www.dtsdoc.com/common_images/windows_update_error2b22.png" alt="SQL Server 2005 SP2 Error 2B22 detail" /><br />
As you can see in the image, the installer was not able to start the service.  (Note that the error number here is 11402; 2B22 in decimal). After checking the service properties, it turned out that it was configured to run under a user account which password had changed recently. I fixed the problem and run the update again. </p>
<p>Once more, the update didn’t succeed. This time the error code was 780. However, now I knew where to look to diagnose the problem:<br />
<img src="http://www.dtsdoc.com/common_images/windows_update_error780.png" alt="SQL Server 2005 SP2 Error 780 detail" /><br />
The service <em>SQL Server VSS Writer (SQLWriter)</em> was disabled. Changing the Start Up property to Manual did the trick. Finally the Service Pack 2 install succeeded.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dbdesc.com/blog/archives/diagnose-sql-server-2005-sp2-install-problems/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Problem dropping a user in SQL 2005</title>
		<link>http://www.dbdesc.com/blog/archives/problem-dropping-a-user-in-sql-2005</link>
		<comments>http://www.dbdesc.com/blog/archives/problem-dropping-a-user-in-sql-2005#comments</comments>
		<pubDate>Tue, 15 May 2007 10:07:03 +0000</pubDate>
		<dc:creator>JAG</dc:creator>
				<category><![CDATA[misc]]></category>
		<category><![CDATA[sqlserver]]></category>

		<guid isPermaLink="false">http://dbdesc.com/blog/archives/problem-dropping-a-user-in-sql-2005</guid>
		<description><![CDATA[Today I’ve encountered a problem trying to drop a user from a database. I kept getting this error: Msg. 15138 The database principal owns a database role and cannot be dropped So it looked like the user owned a database schema. To find out the schemas that a user owns I’ve used this query: SELECT [...]]]></description>
			<content:encoded><![CDATA[<p>Today I’ve encountered a problem trying to drop a user from a database. I kept getting this error:</p>
<p><code><font color="red"> Msg. 15138 The database principal owns a database role and cannot be dropped</font></code></p>
<p>So it looked like the user owned a database schema. To find out the schemas that a user owns I’ve used this query:</p>
<p><code> <font color="blue">SELECT</font> * <font color="blue">FROM</font> <font color="green">INFORMATION_SCHEMA.SCHEMATA </font><font color="blue">WHERE</font> schema_owner = 'UserName'</code></p>
<p><em>UserName</em> was the owner of the <em>dbo_owner</em> schema, so to return the schema to the original owner I’ve executed this other query:</p>
<p><code> <font color="blue">ALTER AUTHORIZATION ON SCHEMA</font>::db_owner <font color="blue">TO</font> dbo</code></p>
<p>Then I’ve been able to drop the user without problems.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dbdesc.com/blog/archives/problem-dropping-a-user-in-sql-2005/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
