<?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>errors &#8211; SQLpowered.com</title>
	<atom:link href="https://sqlpowered.com/tag/errors/feed/" rel="self" type="application/rss+xml" />
	<link>https://sqlpowered.com</link>
	<description>SQL Server + BI</description>
	<lastBuildDate>Mon, 29 Mar 2021 22:20:18 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://sqlpowered.com/wp-content/uploads/2020/07/FavIcon-e1594067873682-99x100.png</url>
	<title>errors &#8211; SQLpowered.com</title>
	<link>https://sqlpowered.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Cannot open database X version 706. Upgrade the database to the latest version.</title>
		<link>https://sqlpowered.com/cannot-open-database-x-version-706-upgrade-the-database-to-the-latest-version/</link>
					<comments>https://sqlpowered.com/cannot-open-database-x-version-706-upgrade-the-database-to-the-latest-version/#respond</comments>
		
		<dc:creator><![CDATA[Jan Dvořák]]></dc:creator>
		<pubDate>Sat, 20 Apr 2019 19:22:04 +0000</pubDate>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[administation]]></category>
		<category><![CDATA[errors]]></category>
		<guid isPermaLink="false">https://sqlpowered.com/?p=3179</guid>

					<description><![CDATA[Past week we were using tool for scanning database metadata across all our production servers and at one of them the tool captured following error when trying to access one of the databases: After some searching and investigating detail about the server we captured two core informations: The database is...]]></description>
										<content:encoded><![CDATA[<p>Past week we were using tool for scanning database metadata across all our production servers and at one of them the tool captured following error when trying to access one of the databases:</p>
<p><img decoding="async" class="alignnone size-full wp-image-3198" src="https://sqlpowered.com/wp-content/uploads/2019/10/Cannot_open_database_Upgrade_1-1.png" alt="" width="722" height="33" srcset="https://sqlpowered.com/wp-content/uploads/2019/10/Cannot_open_database_Upgrade_1-1.png 722w, https://sqlpowered.com/wp-content/uploads/2019/10/Cannot_open_database_Upgrade_1-1-150x7.png 150w, https://sqlpowered.com/wp-content/uploads/2019/10/Cannot_open_database_Upgrade_1-1-300x14.png 300w, https://sqlpowered.com/wp-content/uploads/2019/10/Cannot_open_database_Upgrade_1-1-160x7.png 160w, https://sqlpowered.com/wp-content/uploads/2019/10/Cannot_open_database_Upgrade_1-1-320x15.png 320w, https://sqlpowered.com/wp-content/uploads/2019/10/Cannot_open_database_Upgrade_1-1-520x24.png 520w, https://sqlpowered.com/wp-content/uploads/2019/10/Cannot_open_database_Upgrade_1-1-720x33.png 720w" sizes="(max-width: 722px) 100vw, 722px" /></p>
<p>After some searching and investigating detail about the server we captured two core informations:</p>
<ol>
<li>The database is set for read-only access</li>
<li>The server was upgraded last week to never version (higher service pack).</li>
</ol>
<p>This combination is the root cause of the database to be inaccessible: because it was set read-only during the instance upgrade, setup wasn&#8217;t able to upgrade the database too. The error above appears at every single action to recover now.</p>
<p>All these steps has failed:</p>
<p>1. Set the database for read_write access:</p>
<pre class="lang:tsql decode:true">USE master;  
GO  
ALTER DATABASE [DB1] SET READ_WRITE;  
GO</pre>
<p><img decoding="async" class="alignnone size-full wp-image-3199" src="https://sqlpowered.com/wp-content/uploads/2019/10/Cannot_open_database_Upgrade_2.png" alt="" width="726" height="61" srcset="https://sqlpowered.com/wp-content/uploads/2019/10/Cannot_open_database_Upgrade_2.png 726w, https://sqlpowered.com/wp-content/uploads/2019/10/Cannot_open_database_Upgrade_2-150x13.png 150w, https://sqlpowered.com/wp-content/uploads/2019/10/Cannot_open_database_Upgrade_2-300x25.png 300w, https://sqlpowered.com/wp-content/uploads/2019/10/Cannot_open_database_Upgrade_2-160x13.png 160w, https://sqlpowered.com/wp-content/uploads/2019/10/Cannot_open_database_Upgrade_2-320x27.png 320w, https://sqlpowered.com/wp-content/uploads/2019/10/Cannot_open_database_Upgrade_2-520x44.png 520w, https://sqlpowered.com/wp-content/uploads/2019/10/Cannot_open_database_Upgrade_2-720x60.png 720w" sizes="(max-width: 726px) 100vw, 726px" /></p>
<p>2. Detach the database</p>
<p>3. Backup the database</p>
<p>4. Check if files aren&#8217;t locked at the file system level (read-only attribute)</p>
<p>In the end, we have finished with dropping the database and restoring it from the previous backup which led to successful database version upgrade.</p>
<p>It&#8217;s really one the best practices that before any patching or upgrade of SQL Server instance all read-only database should be set back to read-write mode.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sqlpowered.com/cannot-open-database-x-version-706-upgrade-the-database-to-the-latest-version/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Error in SSMS when expanding Views folder in database created using DBCC CLONEDATABASE</title>
		<link>https://sqlpowered.com/error-in-ssms-when-expanding-views-folder-in-database-created-using-dbcc-clonedatabase/</link>
					<comments>https://sqlpowered.com/error-in-ssms-when-expanding-views-folder-in-database-created-using-dbcc-clonedatabase/#respond</comments>
		
		<dc:creator><![CDATA[Jan Dvořák]]></dc:creator>
		<pubDate>Mon, 26 Mar 2018 10:59:50 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[errors]]></category>
		<guid isPermaLink="false">https://sqlpowered.com/?p=2590</guid>

					<description><![CDATA[SQL Server allows us to create database clone using DBCC CLONEDATABASE command. Cloned database can be then used in SQL Server Management Studio like any other database. But for sure exception exists there: When we will try to browse object contained in cloned database everything works (procedures, functions, ..) until...]]></description>
										<content:encoded><![CDATA[<p>SQL Server allows us to create database clone using DBCC CLONEDATABASE command. Cloned database can be then used in SQL Server Management Studio like any other database. But for sure exception exists there: When we will try to browse object contained in cloned database everything works (procedures, functions, ..) until we will expand Views folder. Then SSMS will throw following exception:</p>
<p><img fetchpriority="high" decoding="async" class="alignnone size-full wp-image-2591" src="https://sqlpowered.com/wp-content/uploads/2018/03/SSMS_Expanding_Views_Error.png" alt="" width="723" height="192" srcset="https://sqlpowered.com/wp-content/uploads/2018/03/SSMS_Expanding_Views_Error.png 723w, https://sqlpowered.com/wp-content/uploads/2018/03/SSMS_Expanding_Views_Error-150x40.png 150w, https://sqlpowered.com/wp-content/uploads/2018/03/SSMS_Expanding_Views_Error-300x80.png 300w, https://sqlpowered.com/wp-content/uploads/2018/03/SSMS_Expanding_Views_Error-160x42.png 160w, https://sqlpowered.com/wp-content/uploads/2018/03/SSMS_Expanding_Views_Error-320x85.png 320w, https://sqlpowered.com/wp-content/uploads/2018/03/SSMS_Expanding_Views_Error-520x138.png 520w, https://sqlpowered.com/wp-content/uploads/2018/03/SSMS_Expanding_Views_Error-720x191.png 720w" sizes="(max-width: 723px) 100vw, 723px" /></p>
<p>There is the query executed by SSMS in the background:</p>
<pre class="lang:default decode:true">exec sp_executesql N'SELECT
v.name AS [Name],
SCHEMA_NAME(v.schema_id) AS [Schema],
''Server[@Name='' + quotename(CAST(
        serverproperty(N''Servername'')
       AS sysname),'''''''') + '']'' + ''/Database[@Name='' + quotename(db_name(),'''''''') + '']'' + ''/View[@Name='' + quotename(v.name,'''''''') 
	   + '' and @Schema='' + quotename(SCHEMA_NAME(v.schema_id),'''''''') + '']'' AS [Urn],
v.create_date AS [CreateDate],
ISNULL(sv.name, N'''') AS [Owner],
CAST(CASE WHEN ISNULL(smv.definition, ssmv.definition) IS NULL THEN 1 ELSE 0 END AS bit) AS [IsEncrypted],
CAST(ISNULL(OBJECTPROPERTYEX(v.object_id, N''IsSchemaBound''),0) AS bit) AS [IsSchemaBound],
CAST(CASE idx.index_id WHEN 1 THEN 1 ELSE 0 END AS bit) AS [HasClusteredIndex]
FROM
sys.all_views AS v
LEFT OUTER JOIN sys.database_principals AS sv ON sv.principal_id = ISNULL(v.principal_id, (OBJECTPROPERTY(v.object_id, ''OwnerId'')))
LEFT OUTER JOIN sys.sql_modules AS smv ON smv.object_id = v.object_id
LEFT OUTER JOIN sys.system_sql_modules AS ssmv ON ssmv.object_id = v.object_id
LEFT OUTER JOIN sys.indexes AS idx ON idx.object_id = v.object_id and (idx.index_id &lt; @_msparam_0)
WHERE
(v.type = @_msparam_1)and(CAST(
 case 
    when v.is_ms_shipped = 1 then 1
    when (
        select 
            major_id 
        from 
            sys.extended_properties 
        where 
            major_id = v.object_id and 
            minor_id = 0 and 
            class = 1 and 
            name = N''microsoft_database_tools_support'') 
        is not null then 1
    else 0
end          
             AS bit)=@_msparam_2)
ORDER BY
[Schema] ASC,[Name] ASC',N'@_msparam_0 nvarchar(4000),@_msparam_1 nvarchar(4000),@_msparam_2 nvarchar(4000)',
@_msparam_0=N'2',@_msparam_1=N'V',@_msparam_2=N'0'</pre>
<p>If we will try to execute this query directly from SSMS we will see this error message:</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-2593" src="https://sqlpowered.com/wp-content/uploads/2018/03/SSMS_Expanding_Views_Error_Text.png" alt="" width="599" height="32" srcset="https://sqlpowered.com/wp-content/uploads/2018/03/SSMS_Expanding_Views_Error_Text.png 599w, https://sqlpowered.com/wp-content/uploads/2018/03/SSMS_Expanding_Views_Error_Text-150x8.png 150w, https://sqlpowered.com/wp-content/uploads/2018/03/SSMS_Expanding_Views_Error_Text-300x16.png 300w, https://sqlpowered.com/wp-content/uploads/2018/03/SSMS_Expanding_Views_Error_Text-160x9.png 160w, https://sqlpowered.com/wp-content/uploads/2018/03/SSMS_Expanding_Views_Error_Text-320x17.png 320w, https://sqlpowered.com/wp-content/uploads/2018/03/SSMS_Expanding_Views_Error_Text-520x28.png 520w" sizes="auto, (max-width: 599px) 100vw, 599px" /></p>
<p>After deeper investigation I have found following single statement is causing the exception:</p>
<pre class="lang:default decode:true">SELECT OBJECTPROPERTY(v.object_id, 'OwnerId')
FROM sys.all_views AS v</pre>
<p>When calling the OBJECTPROPERTY function with &#8216;OwnerId&#8217; as a parameter exception is fired and connection closed. Thankfully this is happening only when querying cloned database and not standard one.</p>
<p>I thought that it can be somehow related to security and SIDs matching in cloned database.</p>
<p>Error was reported to <a href="https://feedback.azure.com/forums/908035-sql-server/suggestions/33760312-error-in-ssms-when-expanding-views-folder-in-datab">Microsoft Azure Feedback</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sqlpowered.com/error-in-ssms-when-expanding-views-folder-in-database-created-using-dbcc-clonedatabase/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Error in transactional replication: &#8216;Incorrect syntax near WHERE&#8217;</title>
		<link>https://sqlpowered.com/replications-incorrect-syntax-near-where/</link>
					<comments>https://sqlpowered.com/replications-incorrect-syntax-near-where/#respond</comments>
		
		<dc:creator><![CDATA[Jan Dvořák]]></dc:creator>
		<pubDate>Tue, 05 Dec 2017 21:05:25 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[errors]]></category>
		<category><![CDATA[replications]]></category>
		<guid isPermaLink="false">https://sqlpowered.com/?p=2294</guid>

					<description><![CDATA[Last week we have seen this error when we have initialized new Subscriber from snapshot that was generated for transactional replication after published database schema was updated: &#8216;An error has occurred: Incorrect syntax near where&#8217; This error occurred after about one hour of applying snapshot to subscribers database and caused...]]></description>
										<content:encoded><![CDATA[<p>Last week we have seen this error when we have initialized new Subscriber from snapshot that was generated for transactional replication after published database schema was updated:<br />
<span style="color: #ff0000;">&#8216;An error has occurred: Incorrect syntax near where&#8217; </span></p>
<p>This error occurred after about one hour of applying snapshot to subscribers database and caused restart of the whole process.</p>
<p>Investigation of error details in distribution database tables was lost time. First after monitoring of the full traffic against the subscriber database we have discovered that our error was caused by this statement:</p>
<pre class="lang:tsql mark:3 decode:true">EXEC(N'
CREATE UNIQUE NONCLUSTERED INDEX [UX_RecordCategory_Record_ID_Category_ID] ON [ts].[RecordCategory]([Record_ID],[Category_ID]) 
WITH (DATA_COMPRESSION = PAGE ) 
WHERE ([Record_ID] IS NOT NULL AND [Category_ID] IS NOT NULL)')</pre>
<p>What&#8217;s wrong there? It&#8217;s maybe not visible at the first look but yes, there is serious syntax error: WITH (DATA_COMPRESSION = PAGE ) should be after the WHERE first:</p>
<pre class="lang:tsql mark:4 decode:true ">EXEC(
N'CREATE UNIQUE NONCLUSTERED INDEX [UX_RecordCategory_Record_ID_Category_ID] ON [ts].[RecordCategory]([Record_ID],[Category_ID]) 
WHERE ([Record_ID] IS NOT NULL AND [Category_ID] IS NOT NULL) 
WITH (DATA_COMPRESSION = PAGE ) 
')</pre>
<p>This invalid statement was hidden in one of *.idx files in snapshot folder. *.idx files are executed as last during snapshot application so this is the reason why we were waiting for this error more than one hour (and 60 GB of data inserted to subscriber DB).</p>
<p>The general message for the whole audience is that you simply cannot generate valid snapshot in case that your database contains filtered indexes with data compression at the same time. MS guys should do better job when testing new features:)</p>
<p>You can check your database for this kind of indexes with this query:</p>
<pre class="lang:tsql decode:true">SELECT *
FROM sys.[indexes] [i]
INNER JOIN sys.[partitions] [p] ON [p].[object_id] = [i].[object_id] AND [p].[index_id] = [i].[index_id]
WHERE [i].[has_filter] = 1 AND [p].[data_compression_desc] &lt;&gt; 'NONE'</pre>
<p>I have created <a href="https://feedback.azure.com/forums/908035-sql-server/suggestions/32898463-replication-snapshot-is-invalid-when-published-dat">Microsoft Collaborate</a> item for this.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sqlpowered.com/replications-incorrect-syntax-near-where/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Could not load type Microsoft.Mashup.Engine.Interface.MashupFileExtension</title>
		<link>https://sqlpowered.com/could-not-load-type-microsoft-mashup-engine-interface-mashupfileextension-error-message/</link>
					<comments>https://sqlpowered.com/could-not-load-type-microsoft-mashup-engine-interface-mashupfileextension-error-message/#respond</comments>
		
		<dc:creator><![CDATA[Jan Dvořák]]></dc:creator>
		<pubDate>Tue, 22 Aug 2017 08:45:46 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[errors]]></category>
		<guid isPermaLink="false">https://sqlpowered.com/?p=2277</guid>

					<description><![CDATA[If you will try to load new data from data source in SSAS tabular project: You can see following error message: There are few options how to solve this issue: https://github.com/Microsoft/DataConnectors/issues/2 In our case it really helped to update SSDT using Visual Studion Tools =&#62; Extensions and Updates: After update was...]]></description>
										<content:encoded><![CDATA[<p>If you will try to load new data from data source in SSAS tabular project:<br />
<img loading="lazy" decoding="async" class="alignnone size-full wp-image-2278" src="https://sqlpowered.com/wp-content/uploads/2017/08/SSDT_Error_MashupLibrary_1.png" alt="" width="314" height="214" /></p>
<p>You can see following error message:</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-2279" src="https://sqlpowered.com/wp-content/uploads/2017/08/SSDT_Error_MashupLibrary_2.png" alt="" width="490" height="185" /></p>
<p><span id="more-2277"></span></p>
<p>There are few options how to solve this issue: <a href="https://github.com/Microsoft/DataConnectors/issues/2">https://github.com/Microsoft/DataConnectors/issues/2</a></p>
<p>In our case it really helped to update SSDT using Visual Studion Tools =&gt; Extensions and Updates:</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-2282" src="https://sqlpowered.com/wp-content/uploads/2017/08/SSDT_Error_MashupLibrary_3.png" alt="" width="617" height="203" /></p>
<p>After update was installed and Visual Studio restarted everything works fine.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sqlpowered.com/could-not-load-type-microsoft-mashup-engine-interface-mashupfileextension-error-message/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>#Errors in SSMS built-in reports</title>
		<link>https://sqlpowered.com/errors-in-ssms-built-in-reports/</link>
					<comments>https://sqlpowered.com/errors-in-ssms-built-in-reports/#comments</comments>
		
		<dc:creator><![CDATA[Jan Dvořák]]></dc:creator>
		<pubDate>Mon, 21 Aug 2017 14:25:20 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[errors]]></category>
		<guid isPermaLink="false">https://sqlpowered.com/?p=2274</guid>

					<description><![CDATA[If you see picture like below in SSMS build in reports (Disk Usage by Top Table in this case) don&#8217;t get panic: It&#8217;s only another funny example of well known Out.Of.Memory exception. Just restart SSMS to get better;).]]></description>
										<content:encoded><![CDATA[<p>If you see picture like below in SSMS build in reports (Disk Usage by Top Table in this case) don&#8217;t get panic: It&#8217;s only another funny example of well known Out.Of.Memory exception. Just restart SSMS to get better;).</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-2275" src="https://sqlpowered.com/wp-content/uploads/2017/08/ErrorInSSMSIBuiltInReport.png" alt="" width="774" height="362" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://sqlpowered.com/errors-in-ssms-built-in-reports/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Error in SSMS data editor when keyword is used in column name with BIT data type</title>
		<link>https://sqlpowered.com/error-in-ssms-data-editor-when-keyword-is-used-in-column-name-with-bit-data-type/</link>
					<comments>https://sqlpowered.com/error-in-ssms-data-editor-when-keyword-is-used-in-column-name-with-bit-data-type/#respond</comments>
		
		<dc:creator><![CDATA[Jan Dvořák]]></dc:creator>
		<pubDate>Sun, 23 Oct 2016 18:53:34 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[errors]]></category>
		<guid isPermaLink="false">https://sqlpowered.com/?p=2143</guid>

					<description><![CDATA[There is still the same bug many years back starting from SSMS 2005. And yes, it is still not corrected in SSMS 2016. If you will create table where one of the columns has name SEND (keyword in SQL Server) and BIT data type, you are not able to edit...]]></description>
										<content:encoded><![CDATA[<p>There is still the same bug many years back starting from SSMS 2005. And yes, it is still not corrected in SSMS 2016. If you will create table where one of the columns has name SEND (keyword in SQL Server) and BIT data type, you are not able to edit table data using data editor. Let´s try it now.<span id="more-2143"></span></p>
<p>Create sample table with one column of BIT datatype called SEND:</p>
<pre class="lang:tsql decode:true">CREATE TABLE [dbo].[TestTable](
	[SEND] [bit] NOT NULL
) ON [PRIMARY]
GO</pre>
<p>Now go to SSMS and open data editor:</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-2189" src="https://sqlpowered.com/wp-content/uploads/2016/10/SSMS-data-editor-error-keyword-1.png" alt="ssms-data-editor-error-keyword-1" width="388" height="235" /></p>
<p>Then edit column value to insert True:</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-2190" src="https://sqlpowered.com/wp-content/uploads/2016/10/SSMS-data-editor-error-keyword-2.png" alt="ssms-data-editor-error-keyword-2" width="513" height="343" /></p>
<p>You can see that an error has occurred. It is not saying to much until you check SQL statements sent from SSMS to SQL engine:</p>
<pre class="lang:tsql decode:true">exec sp_executesql N'INSERT TOP (200) INTO TestTable(SEND) VALUES (@SEND)',N'@SEND bit',@SEND=1
GO

exec sp_executesql N'SELECT TOP (200) SEND FROM TestTable WHERE (''SEND'' = @Param1)',N'@Param1 bit',@Param1=1
GO</pre>
<p>The first statement has completed successfully. But the second one has failed because SEND is an keyword and it is treated as string value and cast to BIT data type has failed. Looks like the issue is that apostrophe is used instead of square brackets.</p>
<p>If we will try the same but instead of SEND we will use column name which isn&#8217;t a keyword, i.e. [AAA], following statement is generated and executed without an error:</p>
<pre class="lang:tsql decode:true">exec sp_executesql N'SELECT TOP (200) AAA FROM TestTable WHERE (AAA = @Param1)',N'@Param1 bit',@Param1=1
GO</pre>
<p>This example is another plus point for the best practice to eliminated key/reserved words in development.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sqlpowered.com/error-in-ssms-data-editor-when-keyword-is-used-in-column-name-with-bit-data-type/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Server Error 601: Could not Continue Scan with NOLOCK due to Data Movement</title>
		<link>https://sqlpowered.com/sql-server-error-601-could-not-continue-scan-with-nolock-due-to-data-movement-2/</link>
					<comments>https://sqlpowered.com/sql-server-error-601-could-not-continue-scan-with-nolock-due-to-data-movement-2/#respond</comments>
		
		<dc:creator><![CDATA[Jan Dvořák]]></dc:creator>
		<pubDate>Thu, 21 Apr 2016 19:49:28 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[errors]]></category>
		<guid isPermaLink="false">https://sqlpowered.com/?p=1512</guid>

					<description><![CDATA[We have noticed the following error message periodically during mass data update on one of our productions servers: ‘Error 601: Could not continue scan with NOLOCK due to data movement’. This server is hosting instance of SQL Server 2008R2 SP1 Standard edition. After some research we have found a detailed...]]></description>
										<content:encoded><![CDATA[<p>We have noticed the following error message periodically during mass data update on one of our productions servers: ‘Error 601: Could not continue scan with NOLOCK due to data movement’. This server is hosting instance of SQL Server 2008R2 SP1 Standard edition. After some research we have found a detailed description of this issue in this KB article: <a href="http://support.microsoft.com/kb/960770/en-us">http://support.microsoft.com/kb/960770/en-us</a>.</p>
<p><span id="more-1512"></span></p>
<p>In our case the error was generated from a code similar to this pattern:</p>
<pre class="lang:tsql decode:true">DECLARE @TempTable TABLE (...)

INSERT INTO @TempTable
    SELECT * FROM ....

INSERT INTO @TempTable
    select *
    from ( select distinct * from @TempTable ) tt
        cross join dbo.TableA a
    where 
        a.Col1 &gt;=  1</pre>
<p>The issue is that data are inserted into @TempTable at the same time when they are retrieved. Writing into this table is causing the reallocation of data pages which should first be read and at the time of reading they aren&#8217;t located at the expected place.</p>
<p>A simple and intuitive solution is code refactoring: Data are inserted into #Distinct temporary table first and after that used to prepare the final data to be inserted into @TempTable. This way we can prevent error to be fired.</p>
<pre class="lang:tsql decode:true ">DECLARE @TempTable TABLE (...)

INSERT INTO @TempTable
    SELECT * FROM ....

SELECT DISTINCT * 
    INTO #Distinct
FROM @TempTable

INSERT INTO @TempTable
    SELECT *
    FROM #Distinct tt
        cross join dbo.TableA a
    WHERE 
        a.Col1 &gt;=  1
GO</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://sqlpowered.com/sql-server-error-601-could-not-continue-scan-with-nolock-due-to-data-movement-2/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Failed to initialize sqlcmd library with error number -2147024809</title>
		<link>https://sqlpowered.com/failed-to-initialize-sqlcmd-library-with-error-number-2147024809/</link>
					<comments>https://sqlpowered.com/failed-to-initialize-sqlcmd-library-with-error-number-2147024809/#respond</comments>
		
		<dc:creator><![CDATA[Jan Dvořák]]></dc:creator>
		<pubDate>Tue, 12 Apr 2016 20:23:01 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[errors]]></category>
		<guid isPermaLink="false">https://sqlpowered.com/?p=1396</guid>

					<description><![CDATA[We have detected the following issue in production after upgrade from SQL Server 2012 SP2 to SQL Server 2014 SP1 with CU5: &#8216;Failed to initialize sqlcmd library with error number -2147024809&#8220;. This message is fired when we try to send an email using sp_send_mail procedure with the query result to...]]></description>
										<content:encoded><![CDATA[<p>We have detected the following issue in production after upgrade from SQL Server 2012 SP2 to SQL Server 2014 SP1 with CU5: &#8216;<em>Failed to initialize sqlcmd library with error number -2147024809</em>&#8220;. This message is fired when we try to send an email using <a href="http://msdn.microsoft.com/en-us/library/ms190307.aspx">sp_send_mail </a>procedure with the query result to be attached or in the body of the email.<span id="more-1396"></span></p>
<p>No one of various suggestions found on the internet helped in our environment (security, etc.) After serious investigation, we found that the issue is presented only with specific values set to sp_send_mail procedure parameters. Following combinations of values is  generating the error:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="sql" data-enlighter-highlight="7-9">EXEC msdb.dbo.sp_send_dbmail
	@profile_name = 'DEFAULT_DBMAIL_PROFILE',
	@recipients = 'test@test.com',
	@subject = 'Test',
	@body = 'Test',
	@query = 'SELECT 1', 
	@query_result_header = 0,
	@query_no_truncate = 1,
	@query_result_no_padding = 0</pre>
<p>As most important looks like the combination of @query_result_header and @query_no_truncated. After doing this change error disappeared. Following is working:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="sql" data-enlighter-highlight="7">EXEC msdb.dbo.sp_send_dbmail
	@profile_name = 'DEFAULT_DBMAIL_PROFILE',
	@recipients = 'test@test.com',
	@subject = 'Test',
	@body = 'Test',
	@query = 'SELECT 1', 
	@query_result_header = 1,
	@query_no_truncate = 1,
	@query_result_no_padding = 0</pre>
<p>We are generating HTML content to the email body and after changing the @query_result_header parameter from 0 to 1 all the logic is working without any change and the email body is delivered as expected.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sqlpowered.com/failed-to-initialize-sqlcmd-library-with-error-number-2147024809/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Server Error 601: Could not continue scan with NOLOCK due to data movement</title>
		<link>https://sqlpowered.com/sql-server-error-601-could-not-continue-scan-with-nolock-due-to-data-movement/</link>
					<comments>https://sqlpowered.com/sql-server-error-601-could-not-continue-scan-with-nolock-due-to-data-movement/#respond</comments>
		
		<dc:creator><![CDATA[Jan Dvořák]]></dc:creator>
		<pubDate>Sat, 06 Feb 2016 21:17:51 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[errors]]></category>
		<guid isPermaLink="false">https://sqlpowered.com/?p=33</guid>

					<description><![CDATA[Na produkčním serveru se pravidelně při větší update dat začalo objevovat následující chybové hlášení: &#8216;Error 601: Could not continue scan with NOLOCK due to data movement&#8217;. Produkční server běží na SQL Server 2008R2 SP1 Standard edition. Po delší hledání se podařilo najít popis chyby v tomto KB:  http://support.microsoft.com/kb/960770/en-us. V našem konkrétním příkladě se...]]></description>
										<content:encoded><![CDATA[<p>Na produkčním serveru se pravidelně při větší update dat začalo objevovat následující chybové hlášení: &#8216;Error 601: Could not continue scan with NOLOCK due to data movement&#8217;. Produkční server běží na SQL Server 2008R2 SP1 Standard edition. Po delší hledání se podařilo najít popis chyby v tomto KB:  <a href="http://support.microsoft.com/kb/960770/en-us">http://support.microsoft.com/kb/960770/en-us</a>.<br />
<span id="more-33"></span></p>
<p>V našem konkrétním příkladě se chyba objevovala v kódu, který využíval následující logiku:</p>
<pre class="lang:tsql decode:true">DECLARE @TempTable TABLE (...)

INSERT INTO @TempTable
    SELECT * FROM ....

INSERT INTO @TempTable
    select *
    from ( select distinct * from @TempTable ) tt
        cross join dbo.TableA a
    where 
        a.Col1 &gt;=  1</pre>
<p>Problematickou operací je zde vkládání do @TempTable ve stejném okamžiku, kdy se z tabulky čte. Zápis do tabulky způsobí realokaci stránek, které mají být teprve přečteny a v okamžiku čtení se již nenacházejí na svém místě.</p>
<p>Řešením je intuitivní přepsání kódu tak, že data se nejprve vloží do dočasné tabulky #Distinct a tato tabulka je následně využita k získání dat pro vložení do @TempTable. Tím se předejde realokaci stránek a výše zmíněné chybě.</p>
<pre class="lang:tsql decode:true">DECLARE @TempTable TABLE (...)

INSERT INTO @TempTable
    SELECT * FROM ....

SELECT DISTINCT * 
    INTO #Distinct
FROM @TempTable

INSERT INTO @TempTable
    SELECT *
    FROM #Distinct tt
        cross join dbo.TableA a
    WHERE 
        a.Col1 &gt;=  1</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://sqlpowered.com/sql-server-error-601-could-not-continue-scan-with-nolock-due-to-data-movement/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
