<?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>DBA &#8211; SQLpowered.com</title>
	<atom:link href="https://sqlpowered.com/category/dba/feed/" rel="self" type="application/rss+xml" />
	<link>https://sqlpowered.com</link>
	<description>SQL Server + BI</description>
	<lastBuildDate>Sat, 23 Mar 2024 11:01: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>DBA &#8211; SQLpowered.com</title>
	<link>https://sqlpowered.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Unraveling the Mystery of the Suspect Pages Table</title>
		<link>https://sqlpowered.com/unraveling-the-mystery-of-the-suspect-pages-table-in-sql-server/</link>
					<comments>https://sqlpowered.com/unraveling-the-mystery-of-the-suspect-pages-table-in-sql-server/#respond</comments>
		
		<dc:creator><![CDATA[Jan Dvořák]]></dc:creator>
		<pubDate>Sat, 23 Mar 2024 11:01:07 +0000</pubDate>
				<category><![CDATA[DBA]]></category>
		<guid isPermaLink="false">https://sqlpowered.com/?p=5666</guid>

					<description><![CDATA[In the vast world of SQL Server, data integrity is paramount. One critical component in maintaining this integrity is the Suspect Pages Table, a feature many database administrators (DBAs) may encounter but not fully understand. This table, an often-overlooked aspect of SQL Server&#8217;s system databases, plays a vital role in...]]></description>
										<content:encoded><![CDATA[<p>In the vast world of SQL Server, data integrity is paramount. One critical component in maintaining this integrity is the Suspect Pages Table, a feature many database administrators (DBAs) may encounter but not fully understand. This table, an often-overlooked aspect of SQL Server&#8217;s system databases, plays a vital role in monitoring and managing potential data corruption.</p>
<h3>What is the Suspect Pages Table?</h3>
<p>Located in the <code>msdb</code> database, the Suspect Pages Table (<code>msdb.dbo.suspect_pages</code>) is essentially a log that SQL Server uses to record information about database pages that it suspects are corrupted. A &#8220;page&#8221; in SQL Server is a basic unit of data storage, consisting of 8 KB. Pages can become suspect due to a variety of reasons, including but not limited to hardware failures, software errors, or issues with the storage system itself.</p>
<h3>How Does SQL Server Use the Suspect Pages Table?</h3>
<p>Whenever SQL Server encounters a problem reading a page due to suspected corruption, it logs an entry in the Suspect Pages Table. This entry includes crucial information such as the database ID, file ID, page number, the type of error encountered, and when the error was logged.</p>
<p>This functionality serves two primary purposes:</p>
<ol>
<li><strong>Alerting and Monitoring:</strong> DBAs can query the table to identify potential issues within their databases, allowing for proactive measures to be taken before the corruption leads to significant data loss or downtime.</li>
<li><strong>Repair Guidance:</strong> The details logged in the Suspect Pages Table can guide DBAs in determining the best course of action for repairing the corruption, whether that be restoring from a backup, running DBCC CHECKDB with appropriate repair options, or other corrective measures.</li>
</ol>
<h3>Interacting with the Suspect Pages Table</h3>
<p>Querying the Suspect Pages Table is straightforward and can provide invaluable insights into the health of a database. Here&#8217;s a simple query to list all suspect pages:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="sql">SELECT * FROM msdb.dbo.suspect_pages;</pre>
<p>This will return a list of all pages that have been marked as suspect, along with details about the corruption. It&#8217;s a good practice for DBAs to regularly monitor this table and set up alerts based on its entries to ensure they are aware of any potential data integrity issues.</p>
<h3>Best Practices for Managing Suspect Pages</h3>
<ol>
<li><strong>Regular Monitoring:</strong> Incorporate checks of the Suspect Pages Table into regular database health assessments.</li>
<li><strong>Prompt Action:</strong> Upon discovering suspect pages, assess the extent of the corruption and take appropriate action immediately to prevent further damage.</li>
<li><strong>Comprehensive Backups:</strong> Maintain a robust backup and recovery strategy. Regular backups can be a lifesaver in the event that data corruption cannot be resolved without data loss.</li>
<li><strong>Investigate Underlying Causes:</strong> After addressing the immediate corruption, investigate the root cause to prevent future occurrences. This may involve hardware diagnostics, reviewing system logs, or considering software updates.</li>
</ol>
<h3>Conclusion</h3>
<p>The Suspect Pages Table in SQL Server is a critical tool in the DBA&#8217;s arsenal for maintaining data integrity and ensuring the health of a database. By understanding how to effectively monitor and respond to entries in this table, DBAs can better protect their organizations from the potentially devastating effects of data corruption. As with many aspects of database administration, proactive vigilance is key to ensuring data remains secure, consistent, and available when needed.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sqlpowered.com/unraveling-the-mystery-of-the-suspect-pages-table-in-sql-server/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>DAC cannot be used to perform database backup</title>
		<link>https://sqlpowered.com/dac-cannot-be-used-to-perform-database-backup/</link>
					<comments>https://sqlpowered.com/dac-cannot-be-used-to-perform-database-backup/#respond</comments>
		
		<dc:creator><![CDATA[Jan Dvořák]]></dc:creator>
		<pubDate>Sun, 07 Feb 2021 17:44:45 +0000</pubDate>
				<category><![CDATA[DBA]]></category>
		<guid isPermaLink="false">https://sqlpowered.com/?p=4886</guid>

					<description><![CDATA[DAC (Dedicated Administrator Connection) is a well-known function of SQL Server for the case that the server isn&#8217;t responding to regular connection for various reasons like heavy-load etc.  Having the magic DAC in the pocket can lead administrators to the opinion that they are save in such a case, that...]]></description>
										<content:encoded><![CDATA[<p>DAC (Dedicated Administrator Connection) is a well-known function of SQL Server for the case that the server isn&#8217;t responding to regular connection for various reasons like heavy-load etc.  Having the magic DAC in the pocket can lead administrators to the opinion that they are save in such a case, that they will simply connect and do all the rescue jobs, i.e. backup critical databases and restore them to another server. But&#8217; that thinking only means that they have forgotten one core limitation the DAC has.</p>
<p>The DAC connection doesn&#8217;t support parallel executed operations like BACKUP and RESTORE are. This means, the when the server isn&#8217;t responding to regular connections we can&#8217;t simply connect to it via DAC and make backups of the critical databases when necessary. If we will try to run BACKUP from it, the following error message will appear:</p>
<p><img decoding="async" class="alignnone wp-image-4887" src="https://sqlpowered.com/wp-content/uploads/2021/02/DAC_Backup_Database_Blocked_Patallel_Operation.png" alt="" width="396" height="55" srcset="https://sqlpowered.com/wp-content/uploads/2021/02/DAC_Backup_Database_Blocked_Patallel_Operation.png 742w, https://sqlpowered.com/wp-content/uploads/2021/02/DAC_Backup_Database_Blocked_Patallel_Operation-300x42.png 300w, https://sqlpowered.com/wp-content/uploads/2021/02/DAC_Backup_Database_Blocked_Patallel_Operation-150x21.png 150w, https://sqlpowered.com/wp-content/uploads/2021/02/DAC_Backup_Database_Blocked_Patallel_Operation-360x50.png 360w, https://sqlpowered.com/wp-content/uploads/2021/02/DAC_Backup_Database_Blocked_Patallel_Operation-160x22.png 160w, https://sqlpowered.com/wp-content/uploads/2021/02/DAC_Backup_Database_Blocked_Patallel_Operation-320x44.png 320w, https://sqlpowered.com/wp-content/uploads/2021/02/DAC_Backup_Database_Blocked_Patallel_Operation-520x72.png 520w, https://sqlpowered.com/wp-content/uploads/2021/02/DAC_Backup_Database_Blocked_Patallel_Operation-720x100.png 720w" sizes="(max-width: 396px) 100vw, 396px" /></p>
<p>There is not much more to say. Simply remember it as a crucial limitation when you will think about your disaster recovery plans.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sqlpowered.com/dac-cannot-be-used-to-perform-database-backup/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>OdbcPrec() and OdbcScale() functions</title>
		<link>https://sqlpowered.com/odbcprec-and-odbcscale-functions/</link>
					<comments>https://sqlpowered.com/odbcprec-and-odbcscale-functions/#respond</comments>
		
		<dc:creator><![CDATA[Jan Dvořák]]></dc:creator>
		<pubDate>Wed, 14 Oct 2020 06:36:55 +0000</pubDate>
				<category><![CDATA[DBA]]></category>
		<guid isPermaLink="false">https://sqlpowered.com/?p=4589</guid>

					<description><![CDATA[I have discovered these two functions accidentally when searching for something else. I was trying to find more information about them but there is nothing in the official documentation and these function can&#8217;t be found in any metadata view like sys.all_object etc. It looks like they exist in SQL Server...]]></description>
										<content:encoded><![CDATA[<p>I have discovered these two functions accidentally when searching for something else. I was trying to find more information about them but there is nothing in the official documentation and these function can&#8217;t be found in any metadata view like <em>sys.all_object</em> etc. It looks like they exist in SQL Server from 2000 edition and they are used internally in special SQL Server objects like <em>sys.spt_columns_odbc_view</em>.</p>
<p>You can review how these two functions behave on any database and compare their results with <em>sys.columns</em> view <em>max_length</em>, <em>precision</em>, and <em>scale</em> columns:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="sql">SELECT DISTINCT *
FROM (
	SELECT 
		t.[name], c.[max_length], c.[precision], 
		OdbcPrec(t.system_type_id, c.max_length, c.precision) odbc_prec,
		c.[scale],
		OdbcScale(t.system_type_id, c.[scale]) odbc_scale
	FROM sys.columns c
	    INNER JOIN sys. t ON [t].[system_type_id] = [c].[system_type_id] AND [t].[user_type_id] = [c].[user_type_id]
	) a    
WHERE ISNULL([max_length], 0) &amp;lt;&amp;gt; ISNULL([odbc_prec], 0) OR
      ISNULL([scale], 0) &amp;lt;&amp;gt; ISNULL(odbc_scale, 0)
GO</pre>
<p><img fetchpriority="high" decoding="async" class="alignnone wp-image-4692" src="https://sqlpowered.com/wp-content/uploads/2020/10/OdbcPrec_OdbcScale_Functions_Not_Found_2.png" alt="" width="385" height="243" srcset="https://sqlpowered.com/wp-content/uploads/2020/10/OdbcPrec_OdbcScale_Functions_Not_Found_2.png 837w, https://sqlpowered.com/wp-content/uploads/2020/10/OdbcPrec_OdbcScale_Functions_Not_Found_2-300x190.png 300w, https://sqlpowered.com/wp-content/uploads/2020/10/OdbcPrec_OdbcScale_Functions_Not_Found_2-150x95.png 150w, https://sqlpowered.com/wp-content/uploads/2020/10/OdbcPrec_OdbcScale_Functions_Not_Found_2-768x485.png 768w, https://sqlpowered.com/wp-content/uploads/2020/10/OdbcPrec_OdbcScale_Functions_Not_Found_2-360x228.png 360w, https://sqlpowered.com/wp-content/uploads/2020/10/OdbcPrec_OdbcScale_Functions_Not_Found_2-160x101.png 160w, https://sqlpowered.com/wp-content/uploads/2020/10/OdbcPrec_OdbcScale_Functions_Not_Found_2-320x202.png 320w, https://sqlpowered.com/wp-content/uploads/2020/10/OdbcPrec_OdbcScale_Functions_Not_Found_2-388x245.png 388w, https://sqlpowered.com/wp-content/uploads/2020/10/OdbcPrec_OdbcScale_Functions_Not_Found_2-538x340.png 538w, https://sqlpowered.com/wp-content/uploads/2020/10/OdbcPrec_OdbcScale_Functions_Not_Found_2-712x450.png 712w, https://sqlpowered.com/wp-content/uploads/2020/10/OdbcPrec_OdbcScale_Functions_Not_Found_2-791x500.png 791w, https://sqlpowered.com/wp-content/uploads/2020/10/OdbcPrec_OdbcScale_Functions_Not_Found_2-520x329.png 520w" sizes="(max-width: 385px) 100vw, 385px" /></p>
<p>Based on this result I will say these two functions are just converting specific SQL Server-related data types length, precision, and scale to ODBC standard specification.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sqlpowered.com/odbcprec-and-odbcscale-functions/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Background process can block restore of database</title>
		<link>https://sqlpowered.com/background-process-can-block-restore-of-database/</link>
					<comments>https://sqlpowered.com/background-process-can-block-restore-of-database/#respond</comments>
		
		<dc:creator><![CDATA[Jan Dvořák]]></dc:creator>
		<pubDate>Sun, 05 Jul 2020 08:49:52 +0000</pubDate>
				<category><![CDATA[DBA]]></category>
		<guid isPermaLink="false">https://sqlpowered.com/?p=3393</guid>

					<description><![CDATA[We can use database snapshots for the development of new databases or fine tunning complex upgrade scripts. All active connections must be closed before the database can be restored from a database snapshot. Closing of active connections manually via Activity Monitor isn&#8217;t an option that can be easily automated so...]]></description>
										<content:encoded><![CDATA[<p>We can use database snapshots for the development of new databases or fine tunning complex upgrade scripts. All active connections must be closed before the database can be restored from a database snapshot. Closing of active connections manually via Activity Monitor isn&#8217;t an option that can be easily automated so we can use this simple batch to close all active connections in the given database before restore:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="sql">USE [master]
GO

DECLARE @Sql VARCHAR(1000)
SET @Sql = ''    
SELECT  @Sql = @Sql + 'kill ' + CONVERT(NVARCHAR(3), [spid]) + '; '
FROM    [master].[dbo].[sysprocesses]
WHERE   DB_NAME([dbid]) = 'MY_DATABASE'  AND spid &gt; 50
EXECUTE(@Sql)
GO</pre>
<p>Most of the time it&#8217;s working perfectly but for some specific databases and only at some point in time we can see this exception to be fired:</p>
<p><img decoding="async" class="alignnone wp-image-4377" src="https://sqlpowered.com/wp-content/uploads/2020/07/SQL-Server-Only-User-Processs-Can-Be-Closed.png" alt="" width="230" height="29" srcset="https://sqlpowered.com/wp-content/uploads/2020/07/SQL-Server-Only-User-Processs-Can-Be-Closed.png 412w, https://sqlpowered.com/wp-content/uploads/2020/07/SQL-Server-Only-User-Processs-Can-Be-Closed-300x38.png 300w, https://sqlpowered.com/wp-content/uploads/2020/07/SQL-Server-Only-User-Processs-Can-Be-Closed-150x19.png 150w, https://sqlpowered.com/wp-content/uploads/2020/07/SQL-Server-Only-User-Processs-Can-Be-Closed-360x45.png 360w, https://sqlpowered.com/wp-content/uploads/2020/07/SQL-Server-Only-User-Processs-Can-Be-Closed-160x20.png 160w, https://sqlpowered.com/wp-content/uploads/2020/07/SQL-Server-Only-User-Processs-Can-Be-Closed-320x40.png 320w" sizes="(max-width: 230px) 100vw, 230px" /></p>
<p>The question is: Is there an active system SPID in our database? Let&#8217;s check it in the Activity Monitor or with the query below:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="sql">SELECT 
	[spid], [kpid], [cmd],  [blocked], [waittype], [waittime], [lastwaittype], [waitresource], [dbid], [uid], [cpu],
	[physical_io], [memusage], [login_time], [last_batch]
FROM    [master].[dbo].[sysprocesses] 
WHERE   DB_NAME([dbid]) = 'MY_DATABASE' 
GO</pre>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-3395" src="https://sqlpowered.com/wp-content/uploads/2019/10/Blocking_System_SPID_Cleanup_Job.png" alt="" width="1099" height="39" srcset="https://sqlpowered.com/wp-content/uploads/2019/10/Blocking_System_SPID_Cleanup_Job.png 1099w, https://sqlpowered.com/wp-content/uploads/2019/10/Blocking_System_SPID_Cleanup_Job-150x5.png 150w, https://sqlpowered.com/wp-content/uploads/2019/10/Blocking_System_SPID_Cleanup_Job-300x11.png 300w, https://sqlpowered.com/wp-content/uploads/2019/10/Blocking_System_SPID_Cleanup_Job-768x27.png 768w, https://sqlpowered.com/wp-content/uploads/2019/10/Blocking_System_SPID_Cleanup_Job-1024x36.png 1024w, https://sqlpowered.com/wp-content/uploads/2019/10/Blocking_System_SPID_Cleanup_Job-160x6.png 160w, https://sqlpowered.com/wp-content/uploads/2019/10/Blocking_System_SPID_Cleanup_Job-320x11.png 320w, https://sqlpowered.com/wp-content/uploads/2019/10/Blocking_System_SPID_Cleanup_Job-520x18.png 520w, https://sqlpowered.com/wp-content/uploads/2019/10/Blocking_System_SPID_Cleanup_Job-720x26.png 720w, https://sqlpowered.com/wp-content/uploads/2019/10/Blocking_System_SPID_Cleanup_Job-980x35.png 980w" sizes="auto, (max-width: 1099px) 100vw, 1099px" /></p>
<p>There is really one active system SPID running and it looks like to do some serious work based on <em>CPU</em> and <em>physical_io</em> columns. Where is this coming from?</p>
<p>Most probably our database has Change Tracking feature active on it and this system SPID is a background task to maintain the history cleanup. We can check for it:</p>
<pre class="lang:tsql decode:true">SELECT * FROM sys.[change_tracking_databases]</pre>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-3398" src="https://sqlpowered.com/wp-content/uploads/2019/10/Blocking_System_SPID_Cleanup_Job_2.png" alt="" width="685" height="58" srcset="https://sqlpowered.com/wp-content/uploads/2019/10/Blocking_System_SPID_Cleanup_Job_2.png 685w, https://sqlpowered.com/wp-content/uploads/2019/10/Blocking_System_SPID_Cleanup_Job_2-150x13.png 150w, https://sqlpowered.com/wp-content/uploads/2019/10/Blocking_System_SPID_Cleanup_Job_2-300x25.png 300w, https://sqlpowered.com/wp-content/uploads/2019/10/Blocking_System_SPID_Cleanup_Job_2-160x14.png 160w, https://sqlpowered.com/wp-content/uploads/2019/10/Blocking_System_SPID_Cleanup_Job_2-320x27.png 320w, https://sqlpowered.com/wp-content/uploads/2019/10/Blocking_System_SPID_Cleanup_Job_2-520x44.png 520w" sizes="auto, (max-width: 685px) 100vw, 685px" /></p>
<p>If we see one row listed there for our database then most probably the system SPID belongs to the Change Tracking cleanup job which is activated on our database and is blocking restore from the snapshot. You can read more about this in the <a href="https://support.microsoft.com/en-us/help/4054842/improvements-to-the-change-tracking-cleanup-process-in-sql-server" rel="noopener noreferrer">documentation</a>. A similar situation we can expect for the Change Data Capture feature.</p>
<p>When Change Tracking doesn&#8217;t need to be active on our development database then the best option is to switch it off before snapshot creation:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="sql">DECLARE @SQL NVARCHAR(MAX) = '';
SELECT @SQL = @SQL + 'ALTER TABLE ' + [s].[name] + '.' + [t].[name] + ' Disable Change_tracking;' + CHAR(10)
FROM [sys].[change_tracking_tables] [ct]
	JOIN [sys].[tables] [t] ON [ct].[object_id]= [t].[object_id] 
	JOIN [sys].[schemas] [s] ON [t].[schema_id]= [s].[schema_id];

EXEC sp_executesql @SQL;
GO

ALTER DATABASE [MY_DATABASE] SET CHANGE_TRACKING = OFF
GO</pre>
<p>If Change Tracking needs to be active we can use the undocumented stored procedure <code><span class="pln"> sp_flush_commit_table_on_demand</span></code>. There is more info about it at <a href="https://sirsql.net/tag/spflushcommittableondemand" rel="noopener noreferrer">sirsql.net</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sqlpowered.com/background-process-can-block-restore-of-database/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<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 loading="lazy" 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="auto, (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 loading="lazy" 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="auto, (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>Kde najít SQL Server 2017 Configuration Manager</title>
		<link>https://sqlpowered.com/kde-najit-sql-server-configuration-manager/</link>
					<comments>https://sqlpowered.com/kde-najit-sql-server-configuration-manager/#respond</comments>
		
		<dc:creator><![CDATA[Jan Dvořák]]></dc:creator>
		<pubDate>Sat, 05 Jan 2019 14:19:53 +0000</pubDate>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[administation]]></category>
		<guid isPermaLink="false">https://sqlpowered.com/?p=2801</guid>

					<description><![CDATA[Když nainstalujete SQL Server 2017 na nejnovější Windows 10 a bude chtít pomocí SQL Server Configuration Manageru změnit parametry instance, bude jeho ikonu hledat v nainstalovaných programech marně. Nově je totiž Configuration Manager distribuován jako snap-in do Microsoft Management Console (mmc.exe) a pokud jej chcete spustit, použijte WIN+R a zadejte:...]]></description>
										<content:encoded><![CDATA[<p>Když nainstalujete SQL Server 2017 na nejnovější Windows 10 a bude chtít pomocí SQL Server Configuration Manageru změnit parametry instance, bude jeho ikonu hledat v nainstalovaných programech marně. Nově je totiž Configuration Manager distribuován jako snap-in do Microsoft Management Console (mmc.exe) a pokud jej chcete spustit, použijte WIN+R a zadejte:</p>
<ul>
<li>SQLServerManager14.msc =&gt; pro SQL Server 2017</li>
<li>SQLServerManager13.msc =&gt; pro SQL Server 2016</li>
<li>SQLServerManager12.msc =&gt; pro SQL Server 2014</li>
<li>SQLServerManager11.msc =&gt; pro SQL Server 2012</li>
</ul>
<p>Pokud si chcete vytvořit zástupce na ploše, najde jednotlivé verze Manageru zde:</p>
<table>
<tbody>
<tr>
<td>SQL Server 2017</td>
<td>C:\Windows\SysWOW64\SQLServerManager14.msc</td>
</tr>
<tr>
<td>SQL Server 2016</td>
<td>C:\Windows\SysWOW64\SQLServerManager13.msc</td>
</tr>
<tr>
<td>SQL Server 2014 (12.x)</td>
<td>C:\Windows\SysWOW64\SQLServerManager12.msc</td>
</tr>
<tr>
<td>SQL Server 2012 (11.x)</td>
<td>C:\Windows\SysWOW64\SQLServerManager11.msc</td>
</tr>
</tbody>
</table>
<p>Více na <a href="https://docs.microsoft.com/en-us/sql/relational-databases/sql-server-configuration-manager?view=sql-server-2017" target="_blank" rel="noopener noreferrer">MSDN &#8211; SQL Server Configuration Manager</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sqlpowered.com/kde-najit-sql-server-configuration-manager/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Extended Events Filter Predicate &#8211; 3000 characters limit</title>
		<link>https://sqlpowered.com/extended-events-filter-predicate-3000-characters-limit/</link>
					<comments>https://sqlpowered.com/extended-events-filter-predicate-3000-characters-limit/#respond</comments>
		
		<dc:creator><![CDATA[Jan Dvořák]]></dc:creator>
		<pubDate>Tue, 27 Feb 2018 21:19:59 +0000</pubDate>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[XE]]></category>
		<guid isPermaLink="false">https://sqlpowered.com/?p=2337</guid>

					<description><![CDATA[If you want to monitor your SQL Server instance traffic using Extended Events and you would like to capture near all statements except some common which are not useful for later analysis you can reach easily maximal limit 3000 characters for filter predicate: There is sample of one filter we...]]></description>
										<content:encoded><![CDATA[<p>If you want to monitor your SQL Server instance traffic using Extended Events and you would like to capture near all statements except some common which are not useful for later analysis you can reach easily maximal limit 3000 characters for filter predicate:</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-2338" src="https://sqlpowered.com/wp-content/uploads/2018/02/ExtendedEvents_3000_limit.png" alt="" width="621" height="210" /></p>
<p><span id="more-2337"></span></p>
<p>There is sample of one filter we are using in production which is near this maximum. You can imagine lot of other things we would like to remove from capturing but we can&#8217;t because of the 3000 characters limit.</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-2339" src="https://sqlpowered.com/wp-content/uploads/2018/02/ExtendedEvents_3000_limit_filter.png" alt="" width="768" height="666" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://sqlpowered.com/extended-events-filter-predicate-3000-characters-limit/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Protect Transactional Replica Against Breaking Data Modifications?</title>
		<link>https://sqlpowered.com/how-to-protect-transactional-replica-against-breaking-data-modifications/</link>
					<comments>https://sqlpowered.com/how-to-protect-transactional-replica-against-breaking-data-modifications/#respond</comments>
		
		<dc:creator><![CDATA[Jan Dvořák]]></dc:creator>
		<pubDate>Fri, 28 Oct 2016 11:18:58 +0000</pubDate>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[replications]]></category>
		<guid isPermaLink="false">https://sqlpowered.com/?p=2129</guid>

					<description><![CDATA[In our scenario we have created transactional replica of our the production database to the staging machine where developers can prepare queries to be later executed in production. But in few days one of developers executed prepared DELETE statement directly against replica and the replication stopped to work with the...]]></description>
										<content:encoded><![CDATA[<p>In our scenario we have created transactional replica of our the production database to the staging machine where developers can prepare queries to be later executed in production. But in few days one of developers executed prepared DELETE statement directly against replica and the replication stopped to work with the error: <a href="https://sqlpowered.com/transactional-replication-error-the-row-was-not-found-at-the-subscriber-when-applying-the-replicated-command/">The row was not found at the Subscriber when applying the replicated command</a>. To prevent this situation we have decided to disable all DML operations against this replica for all accounts except of the system one used by replication agent. After searching for various solutions the easiest way (not saying that the best one) for us was to generate triggers where all transactions from other then replication accounts will be rolled back.<span id="more-2129"></span></p>
<p>Below is simple script to generate required triggers for every table in database. You only need to set @ReplAccount variable to your replication system account. If you will later remove all triggers you can switch @DeleteOnly variable from 0 to 1.</p>
<pre class="lang:tsql decode:true">DECLARE @Stmt NVARCHAR(MAX)
DECLARE @DeleteOnly BIT
DECLARE @ReplAccount NVARCHAR(128)

SET @ReplAccount = 'domain\account'
SET @DeleteOnly = 0

SET @Stmt = ''

SELECT 
	@Stmt = @Stmt + 
	CASE @DeleteOnly 
		WHEN 0 THEN 
			N'EXECUTE(''CREATE TRIGGER ['+ [sch].[name] + '].[trg_prevent_modify_' + [tab].[name] + '] 
							ON [' + [sch].[name] + '].[' + [tab].[name] + ']
			FOR INSERT, UPDATE, DELETE
			AS
			BEGIN
				IF SUSER_SNAME() &lt;&gt; ''''' + @ReplAccount + '''''
				BEGIN
					RAISERROR(''''Database is replicated and data cannot be modified!'''',16,1);
					ROLLBACK;
				END
			END'');

			'
		ELSE 'DROP TRIGGER ['+[sch].[name]+'].[trg_prevent_modify_'+[tab].[name]+']' + CHAR(13)
	END
FROM sys.tables AS tab
	JOIN sys.schemas AS sch ON tab.[schema_id] = sch.[schema_id]
WHERE tab.[type] = 'U'

PRINT @Stmt
EXECUTE(@Stmt)
GO</pre>
<p>If you will test this solution the try to update the data in any table and the following exception will be generated:</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-2219" src="https://sqlpowered.com/wp-content/uploads/2016/10/Trigger_To_Prevent_Replica_To_Be_Updated_Exception.png" alt="trigger_to_prevent_replica_to_be_updated_exception" width="892" height="80" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://sqlpowered.com/how-to-protect-transactional-replica-against-breaking-data-modifications/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Transactional Replication Error: The row was not found at the Subscriber when applying the replicated command.</title>
		<link>https://sqlpowered.com/transactional-replication-error-the-row-was-not-found-at-the-subscriber-when-applying-the-replicated-command/</link>
					<comments>https://sqlpowered.com/transactional-replication-error-the-row-was-not-found-at-the-subscriber-when-applying-the-replicated-command/#comments</comments>
		
		<dc:creator><![CDATA[Jan Dvořák]]></dc:creator>
		<pubDate>Mon, 18 Jul 2016 17:19:44 +0000</pubDate>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[replications]]></category>
		<guid isPermaLink="false">https://sqlpowered.com/?p=2122</guid>

					<description><![CDATA[We are using transactional replication to publish production data for the developers that they can test bugs and other stuff on the subscriber database with near-live data. From time to time they do a mistake and modify data on subscribers and the result is that replication is broken. In this...]]></description>
										<content:encoded><![CDATA[<p>We are using transactional replication to publish production data for the developers that they can test bugs and other stuff on the subscriber database with near-live data. From time to time they do a mistake and modify data on subscribers and the result is that replication is broken. In this post, I will show you few simple steps on how to find more details in case your replication is reporting an error that the row was not found at the Subscriber when applying the replicated command.<span id="more-2122"></span></p>
<p>Usually, you will capture this error in Replication Monitor as visible in this picture:</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-2125" src="https://sqlpowered.com/wp-content/uploads/2016/07/Transactional-Replication-Error.png" alt="Transactional-Replication-Error" width="708" height="577" /></p>
<p>As a first step, we need to browse replication commands that are waiting in the <em>distribution</em> database to be replayed on subscribers. We will select these data from the <a href="https://msdn.microsoft.com/en-us/library/ms188765.aspx">Msrepl_errors</a> table:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="sql">USE [distribution]
GO

SELECT 
	[id], [time], [error_code], [error_text], [xact_seqno]
FROM [dbo].[MSrepl_errors] 
ORDER BY [time] desc
GO</pre>
<p>Once we have selected our error rising command the most important information is hidden in <em>the xact_seqno</em> column: it&#8217;s the starting transaction log sequence number of the first failed transaction in the execution batch.</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-2124" src="https://sqlpowered.com/wp-content/uploads/2016/07/Transactional-Replication-MSrepl_errors.png" alt="Transactional-Replication-MSrepl_errors" width="865" height="77" /></p>
<p>We will use this sequence number as an input parameter for <a href="https://msdn.microsoft.com/en-us/library/ms176109.aspx">sys.sp_browsereplcmds</a> stored procedure which returns a readable version of the replicated commands stored in the distribution database.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="sql">USE [distribution]
GO

EXEC [sys].[sp_browsereplcmds]
	 @xact_seqno_start = N'0x0000A31F0007BC9E01A200000000',
     @xact_seqno_end = N'0x0000A31F0007BC9E01A200000000'
GO</pre>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-2123" src="https://sqlpowered.com/wp-content/uploads/2016/07/Transactional-Replication-sp_browsereplcmds.png" alt="Transactional-Replication-sp_browsereplcmds" width="656" height="96" /></p>
<p>In the <em>command</em> column is the user-friendly text representation of the command to be replicated. The most important part of it is the number in parentheses which is in our particular case the primary key value of the row that should be deleted by this command. And because this row was deleted on the subscriber manually, a replication error is raised when this command is executed on the subscriber.</p>
<p>If we have the option to insert deleted rows on subscriber manually, replication will continue without an error and there is no need for subscription reinitialization.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sqlpowered.com/transactional-replication-error-the-row-was-not-found-at-the-subscriber-when-applying-the-replicated-command/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>How to log SQL Server error messages to SQL/Windows error logs?</title>
		<link>https://sqlpowered.com/sp_altermessage/</link>
					<comments>https://sqlpowered.com/sp_altermessage/#respond</comments>
		
		<dc:creator><![CDATA[Jan Dvořák]]></dc:creator>
		<pubDate>Fri, 08 May 2015 05:57:36 +0000</pubDate>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[administation]]></category>
		<guid isPermaLink="false">https://sqlpowered.com/?p=646</guid>

					<description><![CDATA[Is there an option how to log various SQL Server error messages to SQL Server Error Log and to Windows Error Log? There is one and very simple: we can use system stored procedure sp_altermessage to alter system (message_id &#60; 50 000) messages or user defined messages to be forwarder...]]></description>
										<content:encoded><![CDATA[<p>Is there an option how to log various SQL Server error messages to SQL Server Error Log and to Windows Error Log? There is one and very simple: we can use system stored procedure <a href="https://docs.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-altermessage-transact-sql?view=sql-server-2017" target="_blank" rel="noopener noreferrer">sp_altermessage</a> to alter system (message_id &lt; 50 000) messages or user defined messages to be forwarder to both logs.<span id="more-646"></span>Let see an example:</p>
<pre class="lang:tsql decode:true">EXEC sp_altermessage 102, 'WITH_LOG', 'true'
EXEC sp_altermessage 208, 'WITH_LOG', 'true'
GO

SELECT * F_ROM dbo.table1
GO
SELECT * FROM dbo.invalid_name
GO
</pre>
<p>We have altered two system messages to be stored in SQL/WINDOWS logs:</p>
<p><strong>SQL Server Log:</strong></p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-2985" src="https://sqlpowered.com/wp-content/uploads/2015/05/sp_altermessage_SQL_Serve_Log.png" alt="" width="724" height="658" srcset="https://sqlpowered.com/wp-content/uploads/2015/05/sp_altermessage_SQL_Serve_Log.png 724w, https://sqlpowered.com/wp-content/uploads/2015/05/sp_altermessage_SQL_Serve_Log-110x100.png 110w, https://sqlpowered.com/wp-content/uploads/2015/05/sp_altermessage_SQL_Serve_Log-300x273.png 300w, https://sqlpowered.com/wp-content/uploads/2015/05/sp_altermessage_SQL_Serve_Log-160x145.png 160w, https://sqlpowered.com/wp-content/uploads/2015/05/sp_altermessage_SQL_Serve_Log-320x291.png 320w, https://sqlpowered.com/wp-content/uploads/2015/05/sp_altermessage_SQL_Serve_Log-270x245.png 270w, https://sqlpowered.com/wp-content/uploads/2015/05/sp_altermessage_SQL_Serve_Log-374x340.png 374w, https://sqlpowered.com/wp-content/uploads/2015/05/sp_altermessage_SQL_Serve_Log-495x450.png 495w, https://sqlpowered.com/wp-content/uploads/2015/05/sp_altermessage_SQL_Serve_Log-550x500.png 550w, https://sqlpowered.com/wp-content/uploads/2015/05/sp_altermessage_SQL_Serve_Log-520x473.png 520w" sizes="auto, (max-width: 724px) 100vw, 724px" /></p>
<p><strong>WINDOWS Applications Log:</strong></p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-2986" src="https://sqlpowered.com/wp-content/uploads/2015/05/sp_altermessage_SQL_Serve_Windows_Log.png" alt="" width="759" height="592" srcset="https://sqlpowered.com/wp-content/uploads/2015/05/sp_altermessage_SQL_Serve_Windows_Log.png 759w, https://sqlpowered.com/wp-content/uploads/2015/05/sp_altermessage_SQL_Serve_Windows_Log-128x100.png 128w, https://sqlpowered.com/wp-content/uploads/2015/05/sp_altermessage_SQL_Serve_Windows_Log-300x234.png 300w, https://sqlpowered.com/wp-content/uploads/2015/05/sp_altermessage_SQL_Serve_Windows_Log-160x125.png 160w, https://sqlpowered.com/wp-content/uploads/2015/05/sp_altermessage_SQL_Serve_Windows_Log-320x250.png 320w, https://sqlpowered.com/wp-content/uploads/2015/05/sp_altermessage_SQL_Serve_Windows_Log-314x245.png 314w, https://sqlpowered.com/wp-content/uploads/2015/05/sp_altermessage_SQL_Serve_Windows_Log-436x340.png 436w, https://sqlpowered.com/wp-content/uploads/2015/05/sp_altermessage_SQL_Serve_Windows_Log-577x450.png 577w, https://sqlpowered.com/wp-content/uploads/2015/05/sp_altermessage_SQL_Serve_Windows_Log-641x500.png 641w, https://sqlpowered.com/wp-content/uploads/2015/05/sp_altermessage_SQL_Serve_Windows_Log-520x406.png 520w" sizes="auto, (max-width: 759px) 100vw, 759px" /></p>
<p>Both messages are logged there as expected.</p>
<p>The effect of sp_altermessage with the WITH_LOG option is basically the same as of the RAISERROR WITH LOG parameter, except that sp_altermessage changes the logging behavior for all messages fired inside the engine.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sqlpowered.com/sp_altermessage/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
