<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>SQL Server Compact - Compact &amp; Capable : Troubleshooting</title><link>http://blogs.msdn.com/sqlservercompact/archive/tags/Troubleshooting/default.aspx</link><description>Tags: Troubleshooting</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Troubleshooting: Access Violation exception while using SQL Server Compact database with ADO.NET provider</title><link>http://blogs.msdn.com/sqlservercompact/archive/2009/05/06/troubleshooting-access-violation-exception-while-using-sql-server-compact-database-with-ado-net-provider.aspx</link><pubDate>Wed, 06 May 2009 06:26:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9590345</guid><dc:creator>SQLCEBLOG</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/sqlservercompact/comments/9590345.aspx</comments><wfw:commentRss>http://blogs.msdn.com/sqlservercompact/commentrss.aspx?PostID=9590345</wfw:commentRss><description>&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-outline-level: 2" class=MsoNormal&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;U&gt;&lt;SPAN style="COLOR: #4f81bd; FONT-SIZE: 15pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-themecolor: accent1; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-IN" lang=EN-US&gt;&lt;FONT face=Calibri&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/U&gt;&lt;/B&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt; mso-outline-level: 2" class=MsoNormal&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;U&gt;&lt;SPAN style="COLOR: #4f81bd; FONT-SIZE: 15pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-themecolor: accent1; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-IN" lang=EN-US&gt;&lt;FONT face=Calibri&gt;Possible causes for Access Violation exception in general:&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/U&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-IN" lang=EN-US&gt;&lt;o:p&gt;&lt;FONT face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN-BOTTOM: 0pt; VERTICAL-ALIGN: top"&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: black; mso-bidi-theme-font: minor-latin; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin"&gt;&lt;FONT size=3&gt;An access violation occurs in unmanaged or unsafe code when the code attempts to read or write to memory that has not been allocated, or to which it does not have access. This usually occurs because a pointer has a bad value. &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN-BOTTOM: 0pt; VERTICAL-ALIGN: top"&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: black; mso-bidi-theme-font: minor-latin; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin"&gt;&lt;FONT size=3&gt;In programs consisting entirely of verifiable managed code, all references are either valid or null, and access violations are impossible. &lt;U&gt;An &lt;SPAN class=selflink&gt;&lt;STRONG&gt;AccessViolationException&lt;/STRONG&gt;&lt;/SPAN&gt; occurs only when verifiable managed code interacts with unmanaged code or with unsafe managed code&lt;/U&gt;. &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-IN" lang=EN-US&gt;&lt;o:p&gt;&lt;FONT face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-IN" lang=EN-US&gt;&lt;FONT face=Calibri&gt;For more information about this, please visit this &lt;/FONT&gt;&lt;/SPAN&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/system.accessviolationexception.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.accessviolationexception.aspx"&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-IN" lang=EN-US&gt;&lt;FONT face=Calibri&gt;link&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/A&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-IN" lang=EN-US&gt;&lt;FONT face=Calibri&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-IN" lang=EN-US&gt;&lt;o:p&gt;&lt;FONT face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;U&gt;&lt;SPAN style="COLOR: #4f81bd; FONT-SIZE: 15pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-themecolor: accent1; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-IN" lang=EN-US&gt;&lt;FONT face=Calibri&gt;When this exception can be related to SQL Server Compact:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/U&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-IN" lang=EN-US&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-IN" lang=EN-US&gt;&lt;FONT face=Calibri&gt;SQL Server Compact ADO.NET provider DLL [&lt;/FONT&gt;&lt;/SPAN&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/system.data.sqlserverce.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.data.sqlserverce.aspx"&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-IN" lang=EN-US&gt;&lt;FONT face=Calibri&gt;System.Data.SqlServerCe.dll&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/A&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-IN" lang=EN-US&gt;&lt;FONT face=Calibri&gt;] is a managed DLL which interacts with other native DLLs to provide the functionality.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-IN" lang=EN-US&gt;&lt;o:p&gt;&lt;FONT face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-IN" lang=EN-US&gt;&lt;FONT face=Calibri&gt;There are two known issues related to the usage of SQL Server Compact provider which may lead to this Access Violation exception:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-IN" lang=EN-US&gt;&lt;o:p&gt;&lt;FONT face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; TEXT-INDENT: -18pt; MARGIN: 0cm 0cm 0pt 36pt; mso-list: l0 level1 lfo1; mso-add-space: auto" class=MsoListParagraph&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="COLOR: #4f81bd; FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-themecolor: accent1; mso-ansi-language: EN-US; mso-fareast-language: EN-IN" lang=EN-US&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Calibri&gt;1.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="COLOR: #4f81bd; FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-themecolor: accent1; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-IN" lang=EN-US&gt;&lt;FONT face=Calibri&gt;Version Mismatch [3.5 RTM and 3.5 SP1]:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-IN" lang=EN-US&gt;&lt;o:p&gt;&lt;FONT face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-IN" lang=EN-US&gt;&lt;FONT face=Calibri&gt;Access Violation occurs when the loader loads different versions of Managed and Native SQL Server Compact 3.5 DLLs. This issue arises when different versions are available in the box and this happens with Private and Central deployment of SQL Server Compact 3.5.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-IN" lang=EN-US&gt;&lt;o:p&gt;&lt;FONT face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-IN" lang=EN-US&gt;&lt;FONT face=Calibri&gt;To be specific, if &lt;U&gt;SQL Server Compact 3.5 RTM&lt;/U&gt; is pre-installed [centrally deployed] in the box and application built on top of &lt;U&gt;SQL Server Compact 3.5 SP1&lt;/U&gt; privately deploys the SQL Server Compact DLLs.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-IN" lang=EN-US&gt;&lt;o:p&gt;&lt;FONT face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-IN" lang=EN-US&gt;&lt;FONT face=Calibri&gt;In this case, the managed DLL [System.Data.SqlServerCe.dll v3.5.5692.0] will be loaded from private directory but the native DLLs [sqlceme35.dll, sqlceqp35.dll, etc. v3.5.5386.0] might get loaded from the central deployed directory.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-IN" lang=EN-US&gt;&lt;o:p&gt;&lt;FONT face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;A style="mso-comment-reference: m_1; mso-comment-date: 20090427T1016"&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;FONT face=Calibri&gt;If the application is built against SQL Server Compact 3.5 RTM and SQL Server Compact 3.5 SP1 is centrally deployed in the box&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/A&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-comment-continuation: 1"&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-ansi-language: EN-US" lang=EN-US&gt; then the application will start using SQL Compact 3.5 SP1 as there is a redirection entry which redirects an application (Compiled against 3.5 RTM) to use centrally deployed SQL Compact 3.5 SP1.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-IN" lang=EN-US&gt;&lt;o:p&gt;&lt;FONT face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-IN" lang=EN-US&gt;&lt;o:p&gt;&lt;FONT face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-IN" lang=EN-US&gt;&lt;o:p&gt;&lt;FONT face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; TEXT-INDENT: -18pt; MARGIN: 0cm 0cm 0pt 36pt; mso-list: l0 level1 lfo1; mso-add-space: auto" class=MsoListParagraph&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="COLOR: #4f81bd; FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-themecolor: accent1; mso-ansi-language: EN-US; mso-fareast-language: EN-IN" lang=EN-US&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Calibri&gt;2.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="COLOR: #4f81bd; FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-themecolor: accent1; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-IN" lang=EN-US&gt;&lt;FONT face=Calibri&gt;Thread Safety:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-IN" lang=EN-US&gt;&lt;o:p&gt;&lt;FONT face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;FONT face=Calibri&gt;SQL CE objects are not thread-safe and are not thread affinitive either. If an instance of SqlCeConnection or SqlCeTransaction is shared across threads without ensuring thread safety, then that may lead to Access Violation exception.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;U&gt;&lt;SPAN style="COLOR: #4f81bd; FONT-SIZE: 15pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-themecolor: accent1"&gt;&lt;FONT face=Calibri&gt;Work-around if the cause is related to SQL Server Compact:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/U&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;FONT face=Calibri&gt;For the above two issues, there are workarounds available which should be followed to avoid any Access Violation exception.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="COLOR: #4f81bd; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-themecolor: accent1"&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; TEXT-INDENT: -18pt; MARGIN: 0cm 0cm 0pt 36pt; mso-list: l1 level1 lfo2; mso-add-space: auto" class=MsoListParagraph&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="COLOR: #4f81bd; FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-themecolor: accent1"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Calibri&gt;1.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="COLOR: #4f81bd; FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-themecolor: accent1"&gt;&lt;FONT face=Calibri&gt;Version Mismatch:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;o:p&gt;&lt;FONT face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;FONT face=Calibri&gt;One should follow either of the given below approaches to avoid the Access Violation exception:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;o:p&gt;&lt;FONT face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="COLOR: #4f81bd; FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-themecolor: accent1"&gt;Scenario:&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt; &lt;A style="mso-comment-reference: m_2; mso-comment-date: 20090427T1016"&gt;Application built against SQL Server Compact 3.5 SP1 [to be deployed privately] and SQL Server Compact 3.5 RTM centrally deployed.&lt;/A&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;o:p&gt;&lt;FONT face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="COLOR: #4f81bd; FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-themecolor: accent1"&gt;&lt;FONT face=Calibri&gt;Solution:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;FONT face=Calibri&gt;1.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;There should be only one version of SQL Server Compact [v3.5 RTM or v3.5 SP1] installed in the box. The version with which the application is not built against [v3.5 RTM] should be un-installed.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;FONT face=Calibri&gt;2. &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;Install SQL Server Compact [v3.5 SP1] centrally to avoid any future install mismatch.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;o:p&gt;&lt;FONT face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;FONT face=Calibri&gt;Forum thread related to this issue can be found &lt;/FONT&gt;&lt;/SPAN&gt;&lt;A href="http://social.msdn.microsoft.com/Forums/en-US/sqlce/thread/fd60ba69-e4d6-441a-901f-947ac7a46d3c/" mce_href="http://social.msdn.microsoft.com/Forums/en-US/sqlce/thread/fd60ba69-e4d6-441a-901f-947ac7a46d3c/"&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;FONT face=Calibri&gt;here&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/A&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;FONT face=Calibri&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="COLOR: #4f81bd; FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-themecolor: accent1"&gt;&lt;o:p&gt;&lt;FONT face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; TEXT-INDENT: -18pt; MARGIN: 0cm 0cm 0pt 36pt; mso-list: l1 level1 lfo2; mso-add-space: auto" class=MsoListParagraph&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="COLOR: #4f81bd; FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-themecolor: accent1"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Calibri&gt;2.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="COLOR: #4f81bd; FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin; mso-themecolor: accent1"&gt;&lt;FONT face=Calibri&gt;Thread Safety:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;o:p&gt;&lt;FONT face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;FONT face=Calibri&gt;It is recommended that each thread should use a separate connection than sharing across. If there is really a need for sharing SQL CE objects across threads, then the application should serialize access to these objects. &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;o:p&gt;&lt;FONT face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;FONT face=Calibri&gt;Thanks,&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 12pt; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;FONT face=Calibri&gt;Mohammad Imran.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;DIV style="mso-element: comment-list"&gt;&lt;FONT face=Calibri&gt;
&lt;HR class=msocomoff align=left SIZE=1 width="33%"&gt;
&lt;/FONT&gt;&lt;/DIV&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9590345" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/sqlservercompact/archive/tags/Troubleshooting/default.aspx">Troubleshooting</category><category domain="http://blogs.msdn.com/sqlservercompact/archive/tags/Access+Violation/default.aspx">Access Violation</category></item><item><title>After moving the database from one platform to other, the first SqlCeConnection.Open() takes more time</title><link>http://blogs.msdn.com/sqlservercompact/archive/2009/04/01/after-moving-the-database-from-one-platform-to-other-the-first-sqlceconnection-open-takes-more-time.aspx</link><pubDate>Wed, 01 Apr 2009 15:16:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9529517</guid><dc:creator>SQLCEBLOG</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/sqlservercompact/comments/9529517.aspx</comments><wfw:commentRss>http://blogs.msdn.com/sqlservercompact/commentrss.aspx?PostID=9529517</wfw:commentRss><description>&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;B&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 12pt"&gt;&lt;/SPAN&gt;&lt;/B&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;B&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 12pt"&gt;&lt;/SPAN&gt;&lt;/B&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;B&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 12pt"&gt;If you move a SQLCE database from one platform to other, it's&amp;nbsp;first SqlCeConnection.Open()&amp;nbsp;takes more time and also increases the database file size.&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;U&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 12pt"&gt;&lt;/SPAN&gt;&lt;/U&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;U&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 12pt"&gt;The Reason&lt;/SPAN&gt;&lt;/U&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 12pt"&gt;: F&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt"&gt;or an index on string type columns, SQLCE uses &lt;A href="http://msdn.microsoft.com/en-us/library/dd318700(VS.85).aspx"&gt;&lt;FONT color=#800080&gt;LCMapString&lt;/FONT&gt;&lt;/A&gt; API to get the normalized sort key. LCMapString API behavior will be different for different NLS sort versions. &lt;A href="http://msdn.microsoft.com/en-us/library/dd318105(VS.85).aspx"&gt;&lt;FONT color=#800080&gt;NLS sort version&lt;/FONT&gt;&lt;/A&gt; is different for Desktop Windows OS and WM/WCE. During the first database connection open, SQLCE rebuilds all indexes if there is a NLS sort version mismatch with the last accessed OS platform. Index recreation requires space on database file and hence the database file size will be increased. You can use &lt;A href="http://msdn.microsoft.com/en-us/library/system.data.sqlserverce.sqlceengine.compact(VS.85).aspx"&gt;&lt;FONT color=#800080&gt;Compact()&lt;/FONT&gt;&lt;/A&gt;/&lt;A href="http://msdn.microsoft.com/en-us/library/system.data.sqlserverce.sqlceengine.shrink(VS.85).aspx"&gt;&lt;FONT color=#800080&gt;Shrink()&lt;/FONT&gt;&lt;/A&gt; API to get the database file with approximately old file size. &amp;nbsp;Because of this index recreation, first database connection open takes more time as it has to rebuild all indexes. &amp;nbsp;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;B&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt"&gt;Note&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt"&gt;: If your database doesn’t&amp;nbsp;have any indexes you will not see above mentioned symptoms on first connection open.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;B&gt;&lt;U&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt"&gt;&lt;o:p&gt;&lt;SPAN style="TEXT-DECORATION: none"&gt;&lt;/SPAN&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/U&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;B&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt"&gt;&lt;/SPAN&gt;&lt;/B&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;B&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt"&gt;&lt;/SPAN&gt;&lt;/B&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;B&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt"&gt;Don’t inter-op SQLCE 3.0 databases between devices and desktop:&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt"&gt;SQLCE started supporting desktops only from SQLCE 3.1 (3.0.5300.0) release. SQLCE 3.0 doesn’t have index rebuilding logic and the index re-creation was added during SQLCE 3.1 (3.0.5300.0) release as it is required to support platform inter-op for SQLCE databases. &amp;nbsp;On desktop you can open SQLCE 3.0 databases, which were created on devices. Again If you open these databases on SQLCE 3.0 devices, your device app might receive an error/exception.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt"&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="COLOR: #1f497d; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-bidi-font-weight: bold; mso-themecolor: text2; mso-bidi-font-style: italic"&gt;&lt;U&gt;For example:&lt;/U&gt; Opening&amp;nbsp;a SQLCE 3.0&amp;nbsp;database with SSMS will use SQLCE 3.1 bits on desktop and hence it would drop and recreate index data. When this file is copied back to device, index data may not be valid and receive an error/exception.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;o:p&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt"&gt;Namaskaram!&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt"&gt;Manikyam Bavandla&lt;U&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/U&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoPlainText&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9529517" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/sqlservercompact/archive/tags/ADO.NET/default.aspx">ADO.NET</category><category domain="http://blogs.msdn.com/sqlservercompact/archive/tags/Engine/default.aspx">Engine</category><category domain="http://blogs.msdn.com/sqlservercompact/archive/tags/OLEDB/default.aspx">OLEDB</category><category domain="http://blogs.msdn.com/sqlservercompact/archive/tags/Troubleshooting/default.aspx">Troubleshooting</category><category domain="http://blogs.msdn.com/sqlservercompact/archive/tags/Performance/default.aspx">Performance</category></item><item><title>Insight into SQL Server Compact database corruptions</title><link>http://blogs.msdn.com/sqlservercompact/archive/2008/06/25/insight-into-sql-server-compact-database-corruptions.aspx</link><pubDate>Wed, 25 Jun 2008 18:20:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8652383</guid><dc:creator>SQLCEBLOG</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/sqlservercompact/comments/8652383.aspx</comments><wfw:commentRss>http://blogs.msdn.com/sqlservercompact/commentrss.aspx?PostID=8652383</wfw:commentRss><description>&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US" lang=EN-US&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Database corruptions are often the most painful bugs to repro and debug. A good percentage of the&amp;nbsp;SQL Server Compact&amp;nbsp;bugs reported are in this category. However it so turns out that in majority of the cases&amp;nbsp;Compact&amp;nbsp;is not the culprit. Surprised!! Let us see why. &lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;H2 style="MARGIN: 10pt 0cm 0pt"&gt;&lt;SPAN style="mso-ansi-language: EN-US; mso-fareast-font-family: 'Times New Roman'" lang=EN-US&gt;&lt;FONT size=4&gt;&lt;FONT color=#4f81bd&gt;&lt;FONT face=Cambria&gt;How SQL Server Compact detects a file corruption?&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/H2&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US" lang=EN-US&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Compact&amp;nbsp;database comprises of a series of pages, each 4K in size. When a page is written to disk the following sequence of steps is executed.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US" lang=EN-US&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -18pt; MARGIN: 0cm 0cm 0pt 36pt; mso-list: l2 level1 lfo1" class=MsoListParagraph&gt;&lt;SPAN style="mso-ansi-language: EN-US; mso-fareast-font-family: Calibri; mso-bidi-font-family: Calibri" lang=EN-US&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3 face=Calibri&gt;1.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-ansi-language: EN-US" lang=EN-US&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Compute the checksum on the page data and store it as part of the page.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -18pt; MARGIN: 0cm 0cm 0pt 36pt; mso-list: l2 level1 lfo1" class=MsoListParagraph&gt;&lt;SPAN style="mso-ansi-language: EN-US; mso-fareast-font-family: Calibri; mso-bidi-font-family: Calibri" lang=EN-US&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3 face=Calibri&gt;2.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-ansi-language: EN-US" lang=EN-US&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Encrypt the page.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -18pt; MARGIN: 0cm 0cm 0pt 36pt; mso-list: l2 level1 lfo1" class=MsoListParagraph&gt;&lt;SPAN style="mso-ansi-language: EN-US; mso-fareast-font-family: Calibri; mso-bidi-font-family: Calibri" lang=EN-US&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3 face=Calibri&gt;3.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-ansi-language: EN-US" lang=EN-US&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Write to disk at a given file location or offset.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -18pt; MARGIN: 0cm 0cm 0pt 36pt; mso-list: l2 level1 lfo1" class=MsoListParagraph&gt;&lt;SPAN style="mso-ansi-language: EN-US; mso-fareast-font-family: Calibri; mso-bidi-font-family: Calibri" lang=EN-US&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3 face=Calibri&gt;4.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-ansi-language: EN-US" lang=EN-US&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Update system pages/run time cache with the page offset.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US" lang=EN-US&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US" lang=EN-US&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;When a page is read from disk the following sequence of steps is executed.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US" lang=EN-US&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -18pt; MARGIN: 0cm 0cm 0pt 36pt; mso-list: l0 level1 lfo2" class=MsoListParagraph&gt;&lt;SPAN style="mso-ansi-language: EN-US; mso-fareast-font-family: Calibri; mso-bidi-font-family: Calibri" lang=EN-US&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3 face=Calibri&gt;1.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-ansi-language: EN-US" lang=EN-US&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Read from the disk.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -18pt; MARGIN: 0cm 0cm 0pt 36pt; mso-list: l0 level1 lfo2" class=MsoListParagraph&gt;&lt;SPAN style="mso-ansi-language: EN-US; mso-fareast-font-family: Calibri; mso-bidi-font-family: Calibri" lang=EN-US&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3 face=Calibri&gt;2.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-ansi-language: EN-US" lang=EN-US&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Decrypt the page.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -18pt; MARGIN: 0cm 0cm 0pt 36pt; mso-list: l0 level1 lfo2" class=MsoListParagraph&gt;&lt;SPAN style="mso-ansi-language: EN-US; mso-fareast-font-family: Calibri; mso-bidi-font-family: Calibri" lang=EN-US&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3 face=Calibri&gt;3.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-ansi-language: EN-US" lang=EN-US&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Re-compute the checksum and compare it with the expected value. (If it fails page is not fully baked. Meaning file write failed)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -18pt; MARGIN: 0cm 0cm 0pt 36pt; mso-list: l0 level1 lfo2" class=MsoListParagraph&gt;&lt;SPAN style="mso-ansi-language: EN-US; mso-fareast-font-family: Calibri; mso-bidi-font-family: Calibri" lang=EN-US&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3 face=Calibri&gt;4.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-ansi-language: EN-US" lang=EN-US&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Check if this is the same page that we are expecting as per the system pages/ run time cache. (If this fails we lost a complete page write)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US" lang=EN-US&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US" lang=EN-US&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;If (3) or (4) of the above read steps fail, the db is marked as corrupt and any further db activity is suspended till it is repaired successfully.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US" lang=EN-US&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US" lang=EN-US&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Notes: &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -18pt; MARGIN: 0cm 0cm 0pt 36pt; mso-list: l5 level1 lfo3" class=MsoListParagraph&gt;&lt;SPAN style="FONT-FAMILY: Symbol; mso-ansi-language: EN-US; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol" lang=EN-US&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3&gt;·&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-ansi-language: EN-US" lang=EN-US&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Verify reports step (3) errors as “&lt;SPAN style="COLOR: #c00000"&gt;Bad Checksum - idPage: %d, tyPage: %d, iPage: %d&lt;/SPAN&gt;”. &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -18pt; MARGIN: 0cm 0cm 0pt 36pt; mso-list: l5 level1 lfo3" class=MsoListParagraph&gt;&lt;SPAN style="FONT-FAMILY: Symbol; mso-ansi-language: EN-US; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol" lang=EN-US&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3&gt;·&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-ansi-language: EN-US" lang=EN-US&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Verify reports step (4) errors as &lt;SPAN style="COLOR: #c00000"&gt;“Page with valid ordinal not found - idPage: %d, iPage: %d”&lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;H2 style="MARGIN: 10pt 0cm 0pt"&gt;&lt;SPAN style="mso-ansi-language: EN-US; mso-fareast-font-family: 'Times New Roman'" lang=EN-US&gt;&lt;FONT size=4&gt;&lt;FONT color=#4f81bd&gt;&lt;FONT face=Cambria&gt;What could have triggered the corruption?&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/H2&gt;
&lt;P style="TEXT-INDENT: -18pt; MARGIN: 0cm 0cm 0pt 36pt; mso-list: l3 level1 lfo4" class=MsoListParagraph&gt;&lt;SPAN style="mso-ansi-language: EN-US; mso-fareast-font-family: Calibri; mso-bidi-font-family: Calibri" lang=EN-US&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3 face=Calibri&gt;1.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-ansi-language: EN-US" lang=EN-US&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;A simple device on/off or suspend/resume can result in half-baked file. (No reason to panic as we handle this as described in the next section.)&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -18pt; MARGIN: 0cm 0cm 0pt 36pt; mso-list: l3 level1 lfo4" class=MsoListParagraph&gt;&lt;I&gt;&lt;SPAN style="mso-ansi-language: EN-US; mso-fareast-font-family: Calibri; mso-bidi-font-family: Calibri" lang=EN-US&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3 face=Calibri&gt;2.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;SPAN style="mso-ansi-language: EN-US" lang=EN-US&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Compact&amp;nbsp;relies on underlying FAT/TFAT file system to manage the database file. Any bugs in these components can lead to&amp;nbsp;Compact file corruption. Compact stresses file system in many different ways as it tries to keep the file size as small as possible. As it employs shadow paging the writes and reads are quite random. (&lt;I&gt;Note:&lt;/I&gt;&amp;nbsp;&lt;I&gt;6 months back&amp;nbsp;a bug has been identified in FAT/TFAT system that results in a&amp;nbsp;Compact file losing some of the clusters during shrink operation.)&lt;o:p&gt;&lt;/o:p&gt;&lt;/I&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -18pt; MARGIN: 0cm 0cm 0pt 36pt; mso-list: l3 level1 lfo4" class=MsoListParagraph&gt;&lt;SPAN style="mso-ansi-language: EN-US; mso-fareast-font-family: Calibri; mso-bidi-font-family: Calibri" lang=EN-US&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3 face=Calibri&gt;3.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-ansi-language: EN-US" lang=EN-US&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;If SD card is being used for db file storage, it’s being equally stressed as the above. &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -18pt; MARGIN: 0cm 0cm 0pt 36pt; mso-list: l3 level1 lfo4" class=MsoListParagraph&gt;&lt;SPAN style="mso-ansi-language: EN-US; mso-fareast-font-family: Calibri; mso-bidi-font-family: Calibri" lang=EN-US&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3 face=Calibri&gt;4.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-ansi-language: EN-US" lang=EN-US&gt;More importantly SD cards bring in additional complexities during Suspend/Resume cycles. Here is a good blog link: &lt;/SPAN&gt;&lt;SPAN style="COLOR: #1f497d"&gt;&lt;A href="http://blogs.msdn.com/windowsmobile/archive/2007/01/12/everything-you-want-to-know-about-sd.aspx" mce_href="http://blogs.msdn.com/windowsmobile/archive/2007/01/12/everything-you-want-to-know-about-sd.aspx"&gt;&lt;FONT color=#0000ff&gt;http://blogs.msdn.com/windowsmobile/archive/2007/01/12/everything-you-want-to-know-about-sd.aspx&lt;/FONT&gt;&lt;/A&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-ansi-language: EN-US" lang=EN-US&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;H2 style="MARGIN: 10pt 0cm 0pt"&gt;&lt;SPAN style="mso-ansi-language: EN-US; mso-fareast-font-family: 'Times New Roman'" lang=EN-US&gt;&lt;FONT size=4&gt;&lt;FONT color=#4f81bd&gt;&lt;FONT face=Cambria&gt;Am I suggesting&amp;nbsp;SQL Server Compact&amp;nbsp;bugs can’t result in any kind of corruption?&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/H2&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-ansi-language: EN-US" lang=EN-US&gt;Of course&amp;nbsp;Compact code bugs can result in corruption. A lot of them have been found internally before v3.0 release and also reported by customers thereafter. They are more logical in nature like index constraint is compromised or a table page says there are 1000 rows when there are only 55. &amp;nbsp;We did a very good job in fixing these and they are hard to find now. However&amp;nbsp;Compact bugs don’t result in physical corruptions like “checksum errors” or “page missing” errors. &lt;/SPAN&gt;&lt;SPAN style="COLOR: #1f497d; FONT-SIZE: 12pt; mso-ansi-language: EN-US" lang=EN-US&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;H2 style="MARGIN: 10pt 0cm 0pt"&gt;&lt;SPAN style="mso-ansi-language: EN-US; mso-fareast-font-family: 'Times New Roman'" lang=EN-US&gt;&lt;FONT size=4&gt;&lt;FONT color=#4f81bd&gt;&lt;FONT face=Cambria&gt;What does&amp;nbsp;Compact do to prevent corruptions?&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/H2&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US" lang=EN-US&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;We believe most of the corruptions should be due to device suspend/resume or on/off cycles. &amp;nbsp;For ex:&amp;nbsp;Compact is trying to write to a file and the user simply boots his device. Now file is in half-baked state.&amp;nbsp;Or let’s say process gets killed before it can complete the flush cycle. How do we avoid this? &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US" lang=EN-US&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US" lang=EN-US&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Well, we use shadow paging to overcome this situation. We can loosely categorize the db pages into user data pages, system pages and header page. As the name suggests user data pages contain all the user data. Header pages and system pages help us locate a specific user page on the disk. When it’s time to flush the changes to disk, we write shadows of the user data pages first. Then the shadows of the updated system pages are written. Finally the header page is written. The old pages are retained till the header page is updated. This ensures that we have a transactional write to the disk. Either the change is completely present or not.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;H2 style="MARGIN: 10pt 0cm 0pt"&gt;&lt;SPAN style="mso-ansi-language: EN-US; mso-fareast-font-family: 'Times New Roman'" lang=EN-US&gt;&lt;FONT size=4&gt;&lt;FONT color=#4f81bd&gt;&lt;FONT face=Cambria&gt;Conclusion: Why do we still see corruptions?&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/H2&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US" lang=EN-US&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Clearly the above is not enough. Some of the interesting cases are&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -18pt; MARGIN: 0cm 0cm 0pt 36pt; mso-list: l4 level1 lfo5" class=MsoListParagraph&gt;&lt;SPAN style="FONT-FAMILY: Symbol; mso-ansi-language: EN-US; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol" lang=EN-US&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3&gt;·&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&lt;SPAN style="mso-ansi-language: EN-US" lang=EN-US&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;What if any of the underlying systems&amp;nbsp;‘SD card software’&amp;nbsp;or FAT/TFAT has a bug? &lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -18pt; MARGIN: 0cm 0cm 0pt 36pt; mso-list: l1 level1 lfo6" class=MsoListParagraph&gt;&lt;SPAN style="FONT-FAMILY: Symbol; mso-ansi-language: EN-US; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol" lang=EN-US&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3&gt;·&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp; &lt;SPAN style="mso-ansi-language: EN-US" lang=EN-US&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Suspend/resume cycle can result in file buffer loss if SD card is used. So the changes supposed to be written to disk could be lost. &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -18pt; MARGIN: 0cm 0cm 0pt 36pt; mso-list: l1 level1 lfo6" class=MsoListParagraph&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-ansi-language: EN-US" lang=EN-US&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; FONT-SIZE: 11pt; mso-ansi-language: EN-US; mso-fareast-font-family: SimSun; mso-bidi-font-family: 'Times New Roman'; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-theme-font: minor-fareast" lang=EN-US&gt;The intent is not to blame other components. However in the last 3 years, at least 90% of the corruption bugs reported are due to bad checksum. It means disk write is bad for some reason (which is not owned by Compact). &amp;nbsp;The fault is somewhere in the bottom stack and it has to be fixed. Our options are very limited without a repro but we are&amp;nbsp;trying&amp;nbsp;hard to improve our debugging infrastructure. We are hoping that with this knowledge customers will be able to understand the corruptions better and come up with good practices that would vastly reduce these corruptions.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; FONT-SIZE: 11pt; mso-ansi-language: EN-US; mso-fareast-font-family: SimSun; mso-bidi-font-family: 'Times New Roman'; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-theme-font: minor-fareast" lang=EN-US&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US" lang=EN-US&gt;Thanks&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US" lang=EN-US&gt;Raja&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8652383" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/sqlservercompact/archive/tags/Engine/default.aspx">Engine</category><category domain="http://blogs.msdn.com/sqlservercompact/archive/tags/Troubleshooting/default.aspx">Troubleshooting</category></item><item><title>Query performance</title><link>http://blogs.msdn.com/sqlservercompact/archive/2008/04/30/query-performance.aspx</link><pubDate>Wed, 30 Apr 2008 08:15:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8441485</guid><dc:creator>SQLCEBLOG</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/sqlservercompact/comments/8441485.aspx</comments><wfw:commentRss>http://blogs.msdn.com/sqlservercompact/commentrss.aspx?PostID=8441485</wfw:commentRss><description>&lt;P&gt;Understanding the reason for slowness of a SQL query and then tuning to boost it is a slightly complicated process, but it can be extremely rewarding in some cases. In this post, I am going to list down some ways in which you can tune the query performance for SQL Server Compact, along with pointers to relevant online resources. If you are a seasoned database developer, you probably know most of the tricks already.&lt;/P&gt;
&lt;P&gt;Before I jump into it, an overview of the basics first.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Basics:&lt;/B&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;B&gt;&amp;nbsp;Displaying actual and estimated Execution plans for SQL Server Compact: &lt;/B&gt;You should be familiar with Execution Plans (also called as query plans and showplans).&lt;/LI&gt;
&lt;UL&gt;
&lt;LI&gt;For non-parameterized queries: There are several easy ways to do this&lt;/LI&gt;
&lt;UL&gt;
&lt;LI&gt;When database is on a &lt;B&gt;docked device or desktop&lt;/B&gt;: &lt;A href="http://msdn2.microsoft.com/en-us/library/ms172428%28SQL.100%29.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms172428%28SQL.100%29.aspx"&gt;Generate a query plan using SQL Server Management Studio&lt;/A&gt; (SSMS) that gives a nice graphical view of the query plans. (You can connect to the database on device as long as it is docked. No need to copy the file to desktop.)&lt;/LI&gt;
&lt;LI&gt;When database is on a &lt;B&gt;device&lt;/B&gt;:&lt;B&gt; &lt;/B&gt;&lt;A href="http://msdn2.microsoft.com/en-us/library/ms172893%28SQL.100%29.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms172893%28SQL.100%29.aspx"&gt;Generate a query plan using Query Analyzer&lt;/A&gt;. This generates a .sqlplan file that can be viewed graphically in SQL Server Management Studio as before (preferable) or opened as a plain XML file.&lt;/LI&gt;&lt;/UL&gt;
&lt;LI&gt;For Parameterized (as well as non-parameterized) queries:&lt;/LI&gt;
&lt;UL&gt;
&lt;LI&gt;Use the TSQL Statements &lt;A href="http://msdn2.microsoft.com/en-us/library/bb896157%28SQL.100%29.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/bb896157%28SQL.100%29.aspx"&gt;SET SHOWPLAN_XML &lt;/A&gt;&amp;nbsp;(for estimated execution plan) and&amp;nbsp; &lt;A href="http://msdn2.microsoft.com/en-us/library/bb896155%28SQL.100%29.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/bb896155%28SQL.100%29.aspx"&gt;SET STATISTICS_XML&lt;/A&gt; (for actual execution plan), followed by &lt;A href="http://technet.microsoft.com/en-us/library/bb896154%28SQL.100%29.aspx" mce_href="http://technet.microsoft.com/en-us/library/bb896154%28SQL.100%29.aspx"&gt;SELECT @@SHOWPLAN&lt;/A&gt; to generate the query plans.&amp;nbsp; Store the results as an XML file. (&lt;B&gt;Tip&lt;/B&gt;: To view the query plans graphically, just rename the file with a .sqlplan extension and it is ready to be opened in SSMS like an ordinary non-parameterized query plan.)&lt;/LI&gt;&lt;/UL&gt;&lt;/UL&gt;
&lt;LI&gt;Indexes and statistics on indexes:&lt;/LI&gt;
&lt;UL&gt;
&lt;LI&gt;One of the important tasks of the query optimizer is to select the right index to execute the query. An optimizer can make better decisions if it has histogram data (i.e. statistics) about the distribution of values for an index.&lt;/LI&gt;
&lt;UL&gt;
&lt;LI&gt;CREATING/UPDATING/DELETING statistics on an index: SQL Server Compact 3.5 creates statistics on all indexes by default and updates them as required. (You can surely tweak these settings, but it is advisable not to. See &lt;A href="http://msdn2.microsoft.com/en-us/library/ms174436%28SQL.100%29.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms174436%28SQL.100%29.aspx"&gt;CREATE STATISTICS&lt;/A&gt; /&lt;A href="http://msdn2.microsoft.com/en-us/library/ms174025%28SQL.100%29.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms174025%28SQL.100%29.aspx"&gt;UPDATE STATISTICS&lt;/A&gt;/&lt;A href="http://msdn2.microsoft.com/en-us/library/ms173254%28SQL.100%29.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms173254%28SQL.100%29.aspx"&gt;DROP STATISTICS&lt;/A&gt;). &lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;To view the statistics distribution, the built in stored procedure &lt;A href="http://msdn2.microsoft.com/en-us/library/ms174108%28SQL.100%29.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms174108%28SQL.100%29.aspx"&gt;sp_show_statistics&lt;/A&gt; is pretty handy.&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;Statistics were not created by default on primary key indexes till version 3.1, so you might want to check this and add them yourself :- ).&lt;/LI&gt;&lt;/UL&gt;&lt;/UL&gt;
&lt;LI&gt;... A lot of other things too J, but this will do for the time being.&lt;/LI&gt;&lt;/UL&gt;&lt;B&gt;The Meat:&lt;/B&gt; 
&lt;P&gt;If you are trying to improve the performance of your application that uses SQL Server Compact, make sure you have checked the following resources on MSDN already (In this post I will not go into any of them):&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://msdn2.microsoft.com/en-us/library/ms172432%28SQL.100%29.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms172432%28SQL.100%29.aspx"&gt;Database Design and Performance&lt;/A&gt;: This page talks in some detail about the following:&lt;/LI&gt;
&lt;UL&gt;
&lt;LI&gt;Database denormalization&lt;/LI&gt;
&lt;LI&gt;Variable and fixed sized columns&lt;/LI&gt;
&lt;LI&gt;Effect of row and key lengths&lt;/LI&gt;&lt;/UL&gt;
&lt;LI&gt;&lt;A href="http://msdn2.microsoft.com/en-us/library/ms172984%28SQL.100%29.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms172984%28SQL.100%29.aspx"&gt;Query Performance Tuning&lt;/A&gt;: This page explains some of the following:&lt;/LI&gt;
&lt;UL&gt;
&lt;LI&gt;Improving indexes by creating selective indexes, choosing the columns in a multi-column index, issues in indexing a small table etc.&lt;/LI&gt;
&lt;LI&gt;When to create indexes&lt;/LI&gt;
&lt;LI&gt;Using parameterized queries where possible.&lt;/LI&gt;
&lt;LI&gt;Rewrite queries where possible&lt;/LI&gt;
&lt;LI&gt;Using base table cursor (CommandType.TableDirect) mode for simple queries.&lt;/LI&gt;&lt;/UL&gt;&lt;/UL&gt;
&lt;P&gt;(The article on &lt;A href="http://www.microsoft.com/technet/prodtechnol/sql/2000/maintain/ssceqpop.mspx" mce_href="http://www.microsoft.com/technet/prodtechnol/sql/2000/maintain/ssceqpop.mspx"&gt;Query Process Overview and Performance Tuning approaches for SQL Server CE 2.0&lt;/A&gt; covers the same points as above, but I found it better than the MSDN links J. It is relevant for SQL Server Compact 3.5 too.) &lt;/P&gt;
&lt;P&gt;Now here are some additional ways you can improve performance:&lt;/P&gt;
&lt;P&gt;&lt;B&gt;1.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/B&gt;&lt;B&gt;Recompile Stale query plans&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;StoryTime&amp;gt;Sometime back I got a complaint about slow performance of our database even though the user was using parameterized queries and had created the correct indexes everywhere. The sequence in which he was performing operations was something like this:&lt;/P&gt;
&lt;P&gt;-&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Create the full database schema (tables, indexes etc). &lt;/P&gt;
&lt;P&gt;-&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Prepare SqlCeCommand objects for *all* queries that will ever be used by the application.&lt;/P&gt;
&lt;P&gt;-&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Populate the database with actual data. Until now all tables were empty.&lt;/P&gt;
&lt;P&gt;-&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Execute the queries using previously prepared command objects&amp;nbsp; &lt;/P&gt;
&lt;P&gt;What's wrong with this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;A prepared command object (SqlCeCommand) holds a query plan. The query optimizer generated this query plan and had optimized it for the state of database when the plan was generated. In this user's case, the database had just empty tables at that point in time. The optimizer therefore inferred that using a table scan is the best way of executing the query (as opposed to using any index). As a result, all his query plans used just table scans instead of the right indexes even when the table size increased!&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&amp;lt;/StoryTime&amp;gt;&lt;/P&gt;
&lt;P&gt;Moral of the story: Caching query plans is good, but only as long as the state of database when they are compiled is representative of the average state of database during execution. If your data is changing rapidly, it is better to recompile the queries every once in a while. &lt;/P&gt;
&lt;P&gt;So, beware of stale query plans!&lt;/P&gt;
&lt;P&gt;Note that query plans can be cached for both parameterized and non-parameterized queries and you can run into this problem in either case. (Another insider hack: SqlCeCommand.Prepare doesn't really prepare the query plan. It just marks the command object for plan (re)compilation and the plan is compiled when SqlCeCommand.ExecuteXXX is called next time.) &lt;/P&gt;
&lt;P&gt;&lt;B&gt;2.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/B&gt;&lt;B&gt;Impression of using parameterized queries without really using them&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;&lt;I&gt;Question:&lt;/I&gt; What's wrong (rather sub-optimal) with the following code:&lt;/P&gt;
&lt;P&gt;SqlCeCommand cmd = con.CreateCommand();&lt;/P&gt;
&lt;P&gt;cmd.CommandText = "SELECT * FROM table1 WHERE C1_DECIMAL = @p1";&lt;/P&gt;
&lt;P&gt;cmd.Parameters.Add("@p1", SqlDbType.Decimal);&lt;/P&gt;
&lt;P&gt;cmd.Parameters["@p1"].Value = 3.5;&lt;/P&gt;
&lt;P&gt;SqlCeDataReader rdr = cmd.ExecuteReader();&lt;/P&gt;
&lt;P&gt;while (rdr.Read()) { /* read the data */}&lt;/P&gt;
&lt;P&gt;rdr.Close();&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;cmd.Parameters["@p1"].Value = 335.01;&lt;/P&gt;
&lt;P&gt;rdr = cmd.ExecuteReader();&lt;/P&gt;
&lt;P&gt;while (rdr.Read())&amp;nbsp;{&amp;nbsp; /* read the data */&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P&gt;rdr.Close();&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;&lt;I&gt;Answer:&lt;/I&gt; The query plan gets compiled twice, once for every ExecuteReader call! &lt;/P&gt;
&lt;P&gt;&lt;I&gt;Reason:&lt;/I&gt; First time the plan is compiled, the parameter's precision is 2 and scale is 1 (as inferred from its value ‘3.5'). The query plan therefore uses this precision and scale values. The only other values it can accept are those that fit within this range. &lt;/P&gt;
&lt;P&gt;When the query is executed again, the parameter's precision is 5 and scale is 2 (as inferred from its value ‘335.01'). Since it doesn't fit in the parameter as inferred during first plan compilation, the plan is recompiled silently! &lt;/P&gt;
&lt;P&gt;&lt;I&gt;Solution:&lt;/I&gt; If you can anticipate the range (size, precision or scale) of the parameter values, then specify it explicitly. The plan will be generated based on the specified range then. This holds true for all character, binary and numeric types. (The flip side is that for any parameter value that does not fit into the specified range, an error will be thrown.) So the above code can be modified as follows:&lt;/P&gt;
&lt;P&gt;SqlCeCommand cmd = con.CreateCommand();&lt;/P&gt;
&lt;P&gt;cmd.CommandText = "SELECT * FROM [TABLE1] WHERE [C1_DECIMAL] = @p1";&lt;/P&gt;
&lt;P&gt;cmd.Parameters.Add("@p1", SqlDbType.Decimal);&lt;/P&gt;
&lt;P&gt;&lt;B&gt;cmd.Parameters["@p1"].Precision = 10;&amp;nbsp; &lt;/B&gt;// Playing safe by taking a larger range!&lt;/P&gt;
&lt;P&gt;&lt;B&gt;cmd.Parameters["@p1"].Scale = 5;&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;cmd.Parameters["@p1"].Value = 3.5;&lt;/P&gt;
&lt;P&gt;SqlCeDataReader rdr = cmd.ExecuteReader();&lt;/P&gt;
&lt;P&gt;while (rdr.Read()) { /* read the data */}&lt;/P&gt;
&lt;P&gt;rdr.Close();&lt;/P&gt;
&lt;P&gt;cmd.Parameters["@p1"].Value = 335.00;&lt;/P&gt;
&lt;P&gt;rdr = cmd.ExecuteReader();&lt;/P&gt;
&lt;P&gt;while (rdr.Read()){ /* read the data */ }&lt;/P&gt;
&lt;P&gt;rdr.Close();&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;&lt;/P&gt;
&lt;P&gt;&lt;B&gt;3.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/B&gt;&lt;B&gt;Query optimizer did not choose the best index&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;The query optimizer usually does a good job of choosing the index. However, it does it on a best effort basis and there can be cases where it doesn't pick the right index. In such cases, it makes sense to use index hints and outsmart the optimizer:&lt;/P&gt;
&lt;P&gt;E.g.&amp;nbsp; ...FROM [TABLE1] AS T1 JOIN [TABLE2] AS T2...&amp;nbsp; can be rewritten with index hints as&lt;/P&gt;
&lt;P&gt;...FROM [TABLE1] AS T1 WITH (INDEX(IX_On_Table1)) &lt;/P&gt;
&lt;P&gt;&amp;nbsp;JOIN [TABLE2] AS T2 WITH (INDEX(IX_On_Table2))...&lt;/P&gt;
&lt;P&gt;How do you know if your index is indeed better than the index chosen by optimizer?&lt;/P&gt;
&lt;P&gt;Well, the easiest and brute force method is to run the query with and without an index hint and see which is better.&amp;nbsp; I often use the Query Analyzer on device and SSMS on desktop to get the execution times. Another way is to generate query plans for both queries and study them for better predicate matches, index ordering etc.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;4.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/B&gt;&lt;B&gt;Query optimizer did not choose the best join order&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;As in the case of choosing a wrong index, an optimizer can sometimes choose a wrong join order too. Again a corner case, but not impossible to run into. In such cases, you can specify the join order explicitly:&lt;/P&gt;
&lt;P&gt;E.g. ...FROM [TABLE1] AS T1 INNER JOIN [TABLE2] AS T2 ON ...&amp;nbsp; can be rewritten with a forced join order as&amp;nbsp;&lt;/P&gt;
&lt;P&gt;...FROM [TABLE1] AS T1 &lt;/P&gt;
&lt;P&gt;&amp;nbsp;INNER JOIN [TABLE2] AS T2 ON ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;OPTION (FORCE ORDER)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;As with any sort of query hint, you should be extra careful that you are doing the right thing. For instance, the join order chosen for a query can change between multiple runs due to several reasons. The cardinality of the join tables could have changed significantly, or the data distribution could have changed. So even though the join order that you selected at the time of deployment was optimal, it may not remain so all the time. Ordinarily the optimizer would decide the join order on fly and therefore can adjust to such changes. &lt;/P&gt;
&lt;P&gt;Not so when the join order has been forced.&lt;/P&gt;
&lt;P&gt;That's all for the time being.&lt;/P&gt;
&lt;P&gt;-Pragya Agarwal&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8441485" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/sqlservercompact/archive/tags/QueryProcessor/default.aspx">QueryProcessor</category><category domain="http://blogs.msdn.com/sqlservercompact/archive/tags/Troubleshooting/default.aspx">Troubleshooting</category><category domain="http://blogs.msdn.com/sqlservercompact/archive/tags/Performance/default.aspx">Performance</category></item><item><title>"Houston, we got some problem..." and "Houston, we got a problem..." - notice a difference?</title><link>http://blogs.msdn.com/sqlservercompact/archive/2007/12/12/houston-we-got-some-problem-and-houston-we-got-a-problem-notice-a-difference.aspx</link><pubDate>Wed, 12 Dec 2007 13:18:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6745126</guid><dc:creator>SQLCEBLOG</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/sqlservercompact/comments/6745126.aspx</comments><wfw:commentRss>http://blogs.msdn.com/sqlservercompact/commentrss.aspx?PostID=6745126</wfw:commentRss><description>&lt;P mce_keep="true"&gt;So you have run into a problem - how to efficiently report this:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;System configuration:&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;On a Desktop/Server, Run Winver from Start -&amp;gt; Run.&lt;/LI&gt;
&lt;LI&gt;On a Pocket PC, Start -&amp;gt; Settings -&amp;gt; About&lt;/LI&gt;
&lt;LI&gt;On a Smart Phone, a bit more steps - start -&amp;gt; Settings -&amp;gt; More -&amp;gt;About&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Give us all the details you see here.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;SQL CE Version:&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Applies if you had installed SQL CE by various means &amp;lt;VS / SSMS etc.&amp;gt;&lt;/LI&gt;
&lt;LI&gt;Search for the sqlcese*.dll, right click it and give us the version in version tab.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;STRONG&gt;A detailed description of what you are trying to do:&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Include all details like whether you are using Managed /Native code, single/multi-process and a sample code&lt;/LI&gt;
&lt;LI&gt;A small repro of the error you are getting would be great! &amp;lt;In case of corrupt databases, the corrupt database&amp;gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;STRONG&gt;A Dump file if the process has crashed / hung:&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;On a PC, install this wonderful tool - UserDump.exe from &lt;A href="http://support.microsoft.com/kb/241215" mce_href="http://support.microsoft.com/kb/241215"&gt;http://support.microsoft.com/kb/241215&lt;/A&gt;. This tool installs a control panel entry - click this and register your application's name on this. Next time you get a crash in that app, you will get a dump file in the location you specified. Neat isn't it?&lt;/LI&gt;
&lt;UL&gt;
&lt;LI&gt;In case of a hang, use the same tool above to assign a hotkey and dump the process's current state.&lt;/LI&gt;&lt;/UL&gt;&lt;/UL&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;A word of caution, this crash dump file can be pretty big - so ensure you have enough disk space.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;UL&gt;
&lt;LI&gt;On a mobile device, this gets a bit trickier. If you are using Windows CE 5.0+ version, and if you are lucky enough to have an OEM vendor who has enabled Windows Error Reporting, you can get a dump. Read this wonderful article at &lt;A href="http://windowsfordevices.com/articles/AT7568439504.html" mce_href="http://windowsfordevices.com/articles/AT7568439504.html"&gt;http://windowsfordevices.com/articles/AT7568439504.html&lt;/A&gt; by Abraham Kcholi and Gad Meir.&lt;/LI&gt;&lt;/UL&gt;
&lt;UL&gt;
&lt;LI&gt;For older devices &amp;lt;Win CE 4.2 and so on&amp;gt;, contact us with the program and the problem, and we will handle it case by case.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;B&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;&lt;B&gt;P.S:&lt;/B&gt; No, don't upload all the attachments on to the forums:), but keep them handy. The moment we start looking at this, we will be asking for these.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;P.S.2:&lt;/B&gt; First post here - w00t! I am a developer in the engine team of SQL CE and I guess you will see me here time and again!&lt;/P&gt;
&lt;P&gt;&lt;B&gt;&lt;/B&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Nandri!&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Subu Subramanian.&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;There can be hope only for a society which acts as one big family, not as many separate ones. - Anwar el Sadat&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=6745126" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/sqlservercompact/archive/tags/Engine/default.aspx">Engine</category><category domain="http://blogs.msdn.com/sqlservercompact/archive/tags/Troubleshooting/default.aspx">Troubleshooting</category></item><item><title>Can’t find P/Invoke DLL sqlcemeNN.dll</title><link>http://blogs.msdn.com/sqlservercompact/archive/2007/10/26/can-t-find-p-invoke-dll-sqlcemenn-dll.aspx</link><pubDate>Fri, 26 Oct 2007 18:01:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5695383</guid><dc:creator>SQLCEBLOG</dc:creator><slash:comments>19</slash:comments><comments>http://blogs.msdn.com/sqlservercompact/comments/5695383.aspx</comments><wfw:commentRss>http://blogs.msdn.com/sqlservercompact/commentrss.aspx?PostID=5695383</wfw:commentRss><description>&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;FONT face=Calibri size=3&gt;I know this is very annoying, uninformative, directionless…blah blah… error.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;And, kindly pardon me for blogging about this error very lately.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;Better late than never and here it goes.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&lt;STRONG&gt;What are the actual errors?&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;&lt;o:p&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;FONT face=Calibri size=3&gt;1) Can't find P/Invoke DLL sqlceme30.dll&lt;/FONT&gt;&lt;/P&gt;&lt;FONT face=Calibri size=3&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;FONT face=Calibri size=3&gt;2) Can't find P/Invoke DLL sqlceme35.dll&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;FONT face=Calibri size=3&gt;3) Can't find P/Invoke DLL sqlceme40.dll&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;/FONT&gt;&lt;/o:p&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;What exactly this error means?&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;FONT face=Calibri size=3&gt;When a managed assembly (In our case, System.Data.SqlServerCe.dll) is trying to P/Invoke a method on to a native DLL (In our case, sqlcemeNN.dll; where NN stands for version of product 30, 35 …etc), system has failed to find the DLL to load and invoke the method.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;When do we get this error?&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;FONT face=Calibri size=3&gt;We get this error when system cannot find the DLL in the system path, or current process executable path.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;How can one land in this error?&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;What are the probable workarounds or fixes?&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;FONT face=Calibri size=3&gt;There are multiple cases and some of the well known ones are given below:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoListParagraphCxSpFirst style="MARGIN: 0in 0in 0pt 0.25in; TEXT-INDENT: -0.25in; TEXT-ALIGN: justify; mso-list: l0 level1 lfo1; mso-add-space: auto"&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Calibri size=3&gt;1)&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Calibri size=3&gt;Prior to .NET CF 2.0 SP2, there is no concept of GAC on storage card.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;And, if you have installed SQL CE Cab on storage card with .NET CF 2.0 RTM/SP1 on device, our native DLLs end up on storage card and the GAC on the main memory.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;Hence, managed assembly will fail when P/Invoking above method&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoListParagraphCxSpMiddle style="MARGIN: 0in 0in 0pt 0.75in; TEXT-INDENT: -0.25in; TEXT-ALIGN: justify; mso-list: l0 level2 lfo1; mso-add-space: auto"&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Calibri size=3&gt;a.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Calibri size=3&gt;Please use .NET CF SP2 and above&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoListParagraphCxSpMiddle style="MARGIN: 0in 0in 0pt 0.75in; TEXT-INDENT: -0.25in; TEXT-ALIGN: justify; mso-list: l0 level2 lfo1; mso-add-space: auto"&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Calibri size=3&gt;b.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Calibri size=3&gt;Please install the cabs on main memory&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoListParagraphCxSpMiddle style="MARGIN: 0in 0in 0pt 0.75in; TEXT-INDENT: -0.25in; TEXT-ALIGN: justify; mso-list: l0 level2 lfo1; mso-add-space: auto"&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Calibri size=3&gt;c.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Calibri size=3&gt;Please move to SQL CE 3.0 SP2/3.1 and above&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoListParagraphCxSpMiddle style="MARGIN: 0in 0in 0pt 0.25in; TEXT-ALIGN: justify; mso-add-space: auto"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoListParagraphCxSpMiddle style="MARGIN: 0in 0in 0pt 0.25in; TEXT-INDENT: -0.25in; TEXT-ALIGN: justify; mso-list: l0 level1 lfo1; mso-add-space: auto"&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Calibri size=3&gt;2)&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Calibri size=3&gt;You are developing the application for smart devices (Windows CE OS based)&amp;nbsp;and using Visual Studio Auto Deployment (F5) feature.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;And, VS has failed to map the System.Data.SqlServerCe.dll to the right set of cabs to install and just deployed the System.Data.SqlServerCe.dll alone (&lt;B style="mso-bidi-font-weight: normal"&gt;Note: No error is thrown&lt;/B&gt;).&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;In this case, the native DLLs are not deployed.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoListParagraphCxSpMiddle style="MARGIN: 0in 0in 0pt 0.75in; TEXT-INDENT: -0.25in; TEXT-ALIGN: justify; mso-list: l0 level2 lfo1; mso-add-space: auto"&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Calibri size=3&gt;a.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Fix the auto-deployment issues (Don’t ask me how &lt;/FONT&gt;&lt;SPAN style="FONT-FAMILY: Wingdings; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-char-type: symbol; mso-symbol-font-family: Wingdings"&gt;&lt;SPAN style="mso-char-type: symbol; mso-symbol-font-family: Wingdings"&gt;L&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Calibri&gt;)&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Calibri size=3&gt;
&lt;P class=MsoListParagraphCxSpMiddle style="MARGIN: 0in 0in 0pt 0.75in; TEXT-INDENT: -0.25in; TEXT-ALIGN: justify; mso-list: l0 level2 lfo1; mso-add-space: auto"&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Calibri size=3&gt;b.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Remove and add the reference to System.Data.SqlServerCe.&amp;nbsp; This is because, VS IDE stores assembly identity in the project file.&amp;nbsp; Since we have changed the assembly version in SQL CE v3.5 SP1, removing and adding updates the solution to host the right assembly version&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoListParagraphCxSpMiddle style="MARGIN: 0in 0in 0pt 0.75in; TEXT-INDENT: -0.25in; TEXT-ALIGN: justify; mso-list: l0 level2 lfo1; mso-add-space: auto"&gt;c.&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Calibri size=3&gt;Manually copy and install the SQL CE Cabs (all the 3 cabs).&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;They are located under:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;FONT face=Calibri size=3&gt;%VisualStudioInstallRoot%\SmartDevices\SDK\SQL Server\Mobile\v3.0\&amp;lt;platform&amp;gt;\&amp;lt;processor&amp;gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;FONT face=Calibri size=3&gt;OR&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;FONT face=Calibri size=3&gt;%ProgramFiles%\Microsoft SQL Server Compact Edition\&amp;lt;version&amp;gt;\Devices\&amp;lt;platform&amp;gt;\&amp;lt;processor&amp;gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Calibri size=3&gt;3) &amp;nbsp; System has failed to load the sqlcemeNN.dll.&amp;nbsp; To find more details on why system might have failed to load a module is discussed in my &lt;A class="" href="http://blogs.msdn.com/sqlservercompact/archive/2007/10/26/troubleshooting-can-t-load-sqlce-dll.aspx" target=_blank mce_href="http://blogs.msdn.com/sqlservercompact/archive/2007/10/26/troubleshooting-can-t-load-sqlce-dll.aspx"&gt;previous blog post&lt;/A&gt;.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Calibri size=3&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Calibri size=3&gt;4)&amp;nbsp;&amp;nbsp; If your machine is a 64-bit box, you might have been got trapped into default target platform 'Any CPU' trap, please set the target platform as 'x86'.&amp;nbsp; Need more details, please visit ErikEJ's &lt;A class="" href="http://erikej.blogspot.com/2008/01/x64-and-sql-compact.html" target=_blank mce_href="http://erikej.blogspot.com/2008/01/x64-and-sql-compact.html"&gt;blog post&lt;/A&gt;.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;5)&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Calibri size=3&gt;In &lt;I style="mso-bidi-font-style: normal"&gt;all&lt;/I&gt; other cases, please move to SQL CE 3.0 SP2/3.1 and above.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;If possible make sure HKLM\Software\Microsoft\Microsoft SQL Server Compact Edition\&amp;lt;Version&amp;gt;\NativeDir registry points to the directory where our native DLLs are installed.&amp;nbsp; Please consider the WoW registry if running in WoW&amp;nbsp;mode.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Thanks,&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Laxmi Narsimha Rao ORUGANTI&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;[Update: Edited &lt;STRONG&gt;Actual Errors &lt;/STRONG&gt;section to see if it helps in catching Live/Google's eye]&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;FONT face=Calibri size=3&gt;[Update: Added 64-bit box story and also a reference to ErikEJ's &lt;A class="" href="http://erikej.blogspot.com/2008/01/x64-and-sql-compact.html" target=_blank mce_href="http://erikej.blogspot.com/2008/01/x64-and-sql-compact.html"&gt;blog post&lt;/A&gt;]&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=5695383" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/sqlservercompact/archive/tags/Troubleshooting/default.aspx">Troubleshooting</category></item><item><title>Troubleshooting: Can’t load sqlce dll</title><link>http://blogs.msdn.com/sqlservercompact/archive/2007/10/26/troubleshooting-can-t-load-sqlce-dll.aspx</link><pubDate>Fri, 26 Oct 2007 17:01:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5694935</guid><dc:creator>SQLCEBLOG</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/sqlservercompact/comments/5694935.aspx</comments><wfw:commentRss>http://blogs.msdn.com/sqlservercompact/commentrss.aspx?PostID=5694935</wfw:commentRss><description>&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;FONT face=Calibri size=3&gt;SQL Server CE/Comapct uses Windows API LoadLibrary (&lt;/FONT&gt;&lt;A href="http://msdn2.microsoft.com/en-us/library/ms886736.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms886736.aspx"&gt;&lt;FONT face=Calibri color=#800080 size=3&gt;PlatformBuilder&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Calibri size=3&gt; or &lt;/FONT&gt;&lt;A href="http://msdn2.microsoft.com/en-us/library/ms918408.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms918408.aspx"&gt;&lt;FONT face=Calibri color=#800080 size=3&gt;WinCE&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Calibri size=3&gt; or &lt;/FONT&gt;&lt;A href="http://msdn2.microsoft.com/en-us/library/ms684175.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms684175.aspx"&gt;&lt;FONT face=Calibri color=#800080 size=3&gt;Win32&lt;/FONT&gt;&lt;/A&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;) to load the DLLs.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;When LoadLibrary fails to load any SQL CE dll, we throw the error “Can’t load sqlce dll”.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;Now, let’s discuss more on why LoadLibrary can fail.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoListParagraphCxSpFirst style="MARGIN: 0in 0in 0pt 0.25in; TEXT-INDENT: -0.25in; TEXT-ALIGN: justify; mso-list: l0 level1 lfo1; mso-add-space: auto"&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Calibri size=3&gt;1)&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Calibri size=3&gt;Virtual Memory is too low to load the dll&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoListParagraphCxSpFirst style="MARGIN: 0in 0in 0pt 0.25in; TEXT-INDENT: -0.25in; TEXT-ALIGN: justify; mso-list: l0 level1 lfo1; mso-add-space: auto"&gt;&lt;FONT face=Calibri size=3&gt;2)&amp;nbsp;&amp;nbsp; Dependant DLLs are missing&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoListParagraphCxSpLast style="MARGIN: 0in 0in 10pt 0.25in; TEXT-INDENT: -0.25in; TEXT-ALIGN: justify; mso-list: l0 level1 lfo1; mso-add-space: auto"&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT face=Calibri size=3&gt;3)&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Calibri size=3&gt;Windows CE LoadLibrary has done something strange&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;Regarding point (2):&amp;nbsp; Please run depends.exe on&amp;nbsp;our DLLs and make sure your image has got all the required dependant DLLS.&amp;nbsp; Note that, SQL Server CE stack depends on OLEAUTO.DLL, OLE.DLL.&amp;nbsp; Some of the custom built images might not have selected&amp;nbsp;Platform Builder catalog for COM Support and hence system fails to load the&amp;nbsp;module.&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&lt;/FONT&gt;&lt;/o:p&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&lt;/FONT&gt;&lt;/o:p&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;FONT face=Calibri size=3&gt;Regarding&amp;nbsp;point (1) and (3):&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Please read the &lt;/FONT&gt;&lt;A href="http://support.microsoft.com/kb/326163" mce_href="http://support.microsoft.com/kb/326163"&gt;&lt;FONT face=Calibri color=#800080 size=3&gt;KB Article 326163&lt;/FONT&gt;&lt;/A&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt; completely as I am going to highlight few things from that article.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&amp;lt;Extract&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;FONT face=Calibri size=3&gt;When a DLL is loaded in one process, Windows CE &lt;B style="mso-bidi-font-weight: normal"&gt;&lt;U&gt;reserves&lt;/U&gt;&lt;/B&gt; that address space in every process address space. Multiple processes that use the same DLL share it at the same relative address in every process. If your application does not use the same DLL, it cannot use the memory that is reserved for that DLL. In other words, Windows CE does not map a RAM-based DLL at an address where another process maps another DLL. For example, if Process A loads DLL &lt;I&gt;X&lt;/I&gt; at address 0x00970000, Windows CE does not map DLL &lt;I&gt;Y&lt;/I&gt; in the Process B address space at 0x00970000. Instead, Windows CE seeks the next lower address that is available, depending on the size of DLL &lt;I&gt;Y&lt;/I&gt;. So if DLL &lt;I&gt;Y&lt;/I&gt; is in the size range of 128 KB, Windows CE selects 0x00950000 if that address is available for Process B. Because of the way that Windows CE allows processes to share a common DLL, Windows CE does not permit two different processes to load two different DLLs at the same relative address of each process.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&amp;lt;/Extract&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Which means if there are many DLLs loaded by different processes; and your process is last to load your process LoadLibrary might fail as lot of address space is &lt;B style="mso-bidi-font-weight: normal"&gt;&lt;U&gt;reserved&lt;/U&gt;&lt;/B&gt;.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;FONT face=Calibri size=3&gt;The workarounds proposed from the article are:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&amp;lt;Extract&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;FONT face=Calibri size=3&gt;If you determine that your application cannot load a DLL because of a lack of address space for the DLL, consider the following workarounds: &lt;/FONT&gt;&lt;/P&gt;
&lt;TABLE class=MsoNormalTable style="MARGIN: auto auto auto 3.75pt; BORDER-COLLAPSE: collapse; mso-yfti-tbllook: 1184" cellSpacing=0 cellPadding=0 border=0 class="MsoNormalTable"&gt;
&lt;TBODY&gt;
&lt;TR style="mso-yfti-irow: 0; mso-yfti-firstrow: yes"&gt;
&lt;TD class="" style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0in; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0in; PADDING-BOTTOM: 0in; BORDER-LEFT: #d4d0c8; PADDING-TOP: 0in; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent" vAlign=top&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;FONT face=Calibri size=3&gt;1.&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD class="" style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0in; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0in; PADDING-BOTTOM: 0in; BORDER-LEFT: #d4d0c8; PADDING-TOP: 0in; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent" vAlign=top&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;If your application is implemented in Microsoft C or Microsoft C ++, or if your eMbedded Visual Basic application uses custom DLLs, determine whether you use the &lt;B&gt;VirtualAlloc&lt;/B&gt; function with the MEM_TOP_DOWN flag. When you use this flag, you allocate memory as high as possible, and you can cause DLLs to not load. &lt;B&gt;VirtualAlloc&lt;/B&gt; must not use this flag.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="mso-yfti-irow: 1"&gt;
&lt;TD class="" style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0in; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0in; PADDING-BOTTOM: 0in; BORDER-LEFT: #d4d0c8; PADDING-TOP: 0in; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent" vAlign=top&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;FONT face=Calibri size=3&gt;2. &lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD class="" style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0in; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0in; PADDING-BOTTOM: 0in; BORDER-LEFT: #d4d0c8; PADDING-TOP: 0in; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent" vAlign=top&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;If your application uses a lot of small custom DLLs, consolidate the code in one or two DLLs. The minimum address space that a DLL consumes is 64 KB. Therefore, for example, if you design your application so that thirty DLLs all fall between 8 and 10 KB, you &lt;STRONG&gt;waste 1,620 KB &lt;/STRONG&gt;of address space.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="mso-yfti-irow: 2"&gt;
&lt;TD class="" style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0in; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0in; PADDING-BOTTOM: 0in; BORDER-LEFT: #d4d0c8; PADDING-TOP: 0in; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent" vAlign=top&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;FONT face=Calibri size=3&gt;3.&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD class="" style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0in; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0in; PADDING-BOTTOM: 0in; BORDER-LEFT: #d4d0c8; PADDING-TOP: 0in; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent" vAlign=top&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;Break the application down into more than one process. Use one process to load one set of DLLs and then use another to load a different set of DLLs. (Based on the application design, this may not be practical. If both processes must run simultaneously, then it does not help to use two separate processes.)&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="mso-yfti-irow: 3"&gt;
&lt;TD class="" style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0in; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0in; PADDING-BOTTOM: 0in; BORDER-LEFT: #d4d0c8; PADDING-TOP: 0in; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent" vAlign=top&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;FONT face=Calibri size=3&gt;4.&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD class="" style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0in; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0in; PADDING-BOTTOM: 0in; BORDER-LEFT: #d4d0c8; PADDING-TOP: 0in; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent" vAlign=top&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Load all your essential DLLs when you first load the application&lt;/STRONG&gt;. If possible, keep the DLLs loaded. After you make this change in your application, watch to see if memory allocations or other processes do not work as a result. If they do, you must redesign your application to minimize DLL or memory.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="mso-yfti-irow: 4; mso-yfti-lastrow: yes"&gt;
&lt;TD class="" style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0in; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0in; PADDING-BOTTOM: 0in; BORDER-LEFT: #d4d0c8; PADDING-TOP: 0in; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent" vAlign=top&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;FONT face=Calibri size=3&gt;5.&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD class="" style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0in; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0in; PADDING-BOTTOM: 0in; BORDER-LEFT: #d4d0c8; PADDING-TOP: 0in; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent" vAlign=top&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;Redesign the application to use less memory overall. Use only essential DLLs and then unload them if you do not require them. Minimize heap usage, as this impacts how many DLLs can load. Note that references to ActiveX objects do not unload when you set the object variable to &lt;B&gt;Nothing&lt;/B&gt;.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&amp;lt;/Extract &amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;FONT face=Calibri size=3&gt;The work around people could easily try out is (4) and it has worked for few of our customers.&amp;nbsp; The other thing is to try unloading the unused modules using &lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Calibri','sans-serif'; mso-ansi-language: EN-US; mso-fareast-font-family: Calibri; mso-bidi-font-family: 'Times New Roman'; mso-fareast-language: EN-US; mso-bidi-language: AR-SA; mso-fareast-theme-font: minor-latin; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-theme-font: minor-bidi"&gt;CoFreeUnusedLibraries (&lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms679712.aspx" target=_blank mce_href="http://msdn2.microsoft.com/en-us/library/ms679712.aspx"&gt;Win32&lt;/A&gt; or &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/aa911484.aspx" target=_blank mce_href=" http://msdn2.microsoft.com/en-us/library/aa911484.aspx"&gt;WinCE&lt;/A&gt;) API if COM based applications have run. &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Kruthagnyathalu / Dhanyavadamulu / Thanks,&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt; TEXT-ALIGN: justify"&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Laxmi Narsimha Rao ORUGANTI&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=5694935" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/sqlservercompact/archive/tags/Troubleshooting/default.aspx">Troubleshooting</category></item></channel></rss>