<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" version="2.0">
  <channel>
    <title>Dan Miser - ADO.NET</title>
    <link>http://www.distribucon.com/blog/</link>
    <description>Thoughts from Dan Miser</description>
    <language>en-us</language>
    <copyright>Dan Miser</copyright>
    <lastBuildDate>Tue, 03 Feb 2009 04:13:23 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>dmiser@distribucon.com</managingEditor>
    <webMaster>dmiser@distribucon.com</webMaster>
    <item>
      <trackback:ping>http://www.distribucon.com/blog/Trackback.aspx?guid=212da848-68d2-414b-80d3-227a04c29406</trackback:ping>
      <pingback:server>http://www.distribucon.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.distribucon.com/blog/PermaLink,guid,212da848-68d2-414b-80d3-227a04c29406.aspx</pingback:target>
      <dc:creator>Dan Miser</dc:creator>
      <wfw:comment>http://www.distribucon.com/blog/CommentView,guid,212da848-68d2-414b-80d3-227a04c29406.aspx</wfw:comment>
      <wfw:commentRss>http://www.distribucon.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=212da848-68d2-414b-80d3-227a04c29406</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I'm using <a href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlbulkcopy.aspx" target="_blank">SqlBulkCopy</a> to
quickly <a href="http://support.microsoft.com/kb/321686" target="_blank">copy an Excel
spreadsheet into MSSQL</a>. It is lightning fast, and works extremely well. One snag
came up because I <strong>need</strong> to have an Identity field for my primary key
on this newly copied table (the short story is NHibernate's need for a PK, and the
lack of anything resembling a PK in the Excel data due to it coming from legacy data). 
</p>
        <p>
The problem is if you add the Identity field in the first column of the destination
table, SqlBulkCopy will try to line the columns up by position and things break. You
can add ColumnMappings to have SqlBulkCopy write the excel columns to the right MSSQL
table column, but that can be a lot of code if you have a lot of columns.
</p>
        <p>
My solution ended up being to simply add the Identity field to the end of the destination
table. By doing that, the columns line up during the SqlBulkCopy and everything works
just fine.
</p>
        <img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=212da848-68d2-414b-80d3-227a04c29406" />
      </body>
      <title>SqlBulkCopy with Identity fields</title>
      <guid isPermaLink="false">http://www.distribucon.com/blog/PermaLink,guid,212da848-68d2-414b-80d3-227a04c29406.aspx</guid>
      <link>http://www.distribucon.com/blog/SqlBulkCopyWithIdentityFields.aspx</link>
      <pubDate>Tue, 03 Feb 2009 04:13:23 GMT</pubDate>
      <description>&lt;p&gt;
I'm using &lt;a href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlbulkcopy.aspx" target="_blank"&gt;SqlBulkCopy&lt;/a&gt; to
quickly &lt;a href="http://support.microsoft.com/kb/321686" target="_blank"&gt;copy an Excel
spreadsheet into MSSQL&lt;/a&gt;. It is lightning fast, and works extremely well. One snag
came up because I &lt;strong&gt;need&lt;/strong&gt; to have an Identity field for my primary key
on this newly copied table (the short story is NHibernate's need for a PK, and the
lack of anything resembling a PK in the Excel data due to it coming from legacy data). 
&lt;/p&gt;
&lt;p&gt;
The problem is if you add the Identity field in the first column of the destination
table, SqlBulkCopy will try to line the columns up by position and things break. You
can add ColumnMappings to have SqlBulkCopy write the excel columns to the right MSSQL
table column, but that can be a lot of code if you have a lot of columns.
&lt;/p&gt;
&lt;p&gt;
My solution ended up being to simply add the Identity field to the end of the destination
table. By doing that, the columns line up during the SqlBulkCopy and everything works
just fine.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=212da848-68d2-414b-80d3-227a04c29406" /&gt;</description>
      <comments>http://www.distribucon.com/blog/CommentView,guid,212da848-68d2-414b-80d3-227a04c29406.aspx</comments>
      <category>ADO.NET</category>
    </item>
    <item>
      <trackback:ping>http://www.distribucon.com/blog/Trackback.aspx?guid=6677af09-9a90-4175-98f7-e0dd15dbc12e</trackback:ping>
      <pingback:server>http://www.distribucon.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.distribucon.com/blog/PermaLink,guid,6677af09-9a90-4175-98f7-e0dd15dbc12e.aspx</pingback:target>
      <dc:creator>Dan Miser</dc:creator>
      <wfw:comment>http://www.distribucon.com/blog/CommentView,guid,6677af09-9a90-4175-98f7-e0dd15dbc12e.aspx</wfw:comment>
      <wfw:commentRss>http://www.distribucon.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=6677af09-9a90-4175-98f7-e0dd15dbc12e</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">Moving from a legacy system, one needs
to appropriately deal with bad data in the database. For example, in order to put
a primary key on a table, the column(s) in that primary key must be able to uniquely
identify one record. If you need to find rows with duplicate entries before adding
a primary key, you can start with this query: 
<p></p><pre><code> select Id from MyTable group by Id having count(*) &gt; 1 </code></pre><img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=6677af09-9a90-4175-98f7-e0dd15dbc12e" /></body>
      <title>Duplicate values in an MSSQL table</title>
      <guid isPermaLink="false">http://www.distribucon.com/blog/PermaLink,guid,6677af09-9a90-4175-98f7-e0dd15dbc12e.aspx</guid>
      <link>http://www.distribucon.com/blog/DuplicateValuesInAnMSSQLTable.aspx</link>
      <pubDate>Mon, 22 Oct 2007 19:33:51 GMT</pubDate>
      <description>Moving from a legacy system, one needs to appropriately deal with bad data in the database. For example, in order to put a primary key on a table, the column(s) in that primary key must be able to uniquely identify one record. If you need to find rows with duplicate entries before adding a primary key, you can start with this query: &lt;p&gt;
&lt;pre&gt;&lt;code&gt; select Id from MyTable group by Id having count(*) &gt; 1 &lt;/code&gt;&lt;/pre&gt;&lt;img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=6677af09-9a90-4175-98f7-e0dd15dbc12e" /&gt;</description>
      <comments>http://www.distribucon.com/blog/CommentView,guid,6677af09-9a90-4175-98f7-e0dd15dbc12e.aspx</comments>
      <category>ADO.NET</category>
    </item>
    <item>
      <trackback:ping>http://www.distribucon.com/blog/Trackback.aspx?guid=581f6715-2c0c-464d-99ed-b8175209c40b</trackback:ping>
      <pingback:server>http://www.distribucon.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.distribucon.com/blog/PermaLink,guid,581f6715-2c0c-464d-99ed-b8175209c40b.aspx</pingback:target>
      <dc:creator>Dan Miser</dc:creator>
      <wfw:comment>http://www.distribucon.com/blog/CommentView,guid,581f6715-2c0c-464d-99ed-b8175209c40b.aspx</wfw:comment>
      <wfw:commentRss>http://www.distribucon.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=581f6715-2c0c-464d-99ed-b8175209c40b</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">I hate when we lose functionality in applications.
I'm writing a pretty classic ASP.NET application right now. One assembly is the Data
Access Layer, and I try to write enough unit tests to actually show that things stand
a chance of working (both now and in the future). Also, I occasionally like to work
at home, disconnected from work's servers (database and other). That means that I
have MSSQL installed on my laptop, which has local copies of the databases that I
would need. I also have my web.config checked into source control so others on the
team can do a simple checkout and have the web site working with a simple build of
the MSBuild script. Given that setup, how would one go about being a responsible unit
tester? It seems that what I want is a way to set a default connection string in the
main config file, and allow a user.config to (optionally) exist. If it did exist,
it could override the settings that were in the main config file to point to a new
database. 
<p>
There is a new attribute, <a href="http://msdn2.microsoft.com/en-us/library/system.configuration.sectioninformation.configsource.aspx" target="_new">configSource</a>,
that looks promising because it can be used to redirect .NET from looking at the app.config
(or web.config) and instead make it look at an arbitrary generic user.config file
for its content. The problem with this approach is that it <b>requires</b> every machine
to have this user.config file in the same place. What I want is more like what the
old <a href="http://msdn2.microsoft.com/en-us/library/ms228154.aspx" target="_new">file
attribute of appSettings</a> provided. Unfortunately, the new tools in ASP.NET 2.0
get the connection string information from the <a href="http://msdn2.microsoft.com/en-us/library/bf7sd233.aspx" target="_new">connectionStrings
section</a>, so using the appSettings approach is out-dated. 
</p><p>
For now, I'll use configSource, but it is a pain to have to tell each memeber of the
dev team that they need to create their very own user.config file and place it in
a certain directory, since this usage means that you wouldn't want to check user.config
into your source control system. 
</p><p>
Take a look at J.D. Meier's paper, <a href="http://blogs.msdn.com/jmeier/archive/2007/04/21/how-to-reference-web-services-and-databases-during-development.aspx" target="_new">How
To Reference Web Services and Databases During Development</a>, for some concrete
samples on how this looks.
</p><img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=581f6715-2c0c-464d-99ed-b8175209c40b" /></body>
      <title>Using an external config file to control connection strings</title>
      <guid isPermaLink="false">http://www.distribucon.com/blog/PermaLink,guid,581f6715-2c0c-464d-99ed-b8175209c40b.aspx</guid>
      <link>http://www.distribucon.com/blog/UsingAnExternalConfigFileToControlConnectionStrings.aspx</link>
      <pubDate>Tue, 29 May 2007 17:54:59 GMT</pubDate>
      <description>I hate when we lose functionality in applications. I'm writing a pretty classic ASP.NET application right now. One assembly is the Data Access Layer, and I try to write enough unit tests to actually show that things stand a chance of working (both now and in the future). Also, I occasionally like to work at home, disconnected from work's servers (database and other). That means that I have MSSQL installed on my laptop, which has local copies of the databases that I would need. I also have my web.config checked into source control so others on the team can do a simple checkout and have the web site working with a simple build of the MSBuild script. Given that setup, how would one go about being a responsible unit tester? It seems that what I want is a way to set a default connection string in the main config file, and allow a user.config to (optionally) exist. If it did exist, it could override the settings that were in the main config file to point to a new database. 
&lt;p&gt;
There is a new attribute, &lt;a href="http://msdn2.microsoft.com/en-us/library/system.configuration.sectioninformation.configsource.aspx" target=_new&gt;configSource&lt;/a&gt;,
that looks promising because it can be used to redirect .NET from looking at the app.config
(or web.config) and instead make it look at an arbitrary generic user.config file
for its content. The problem with this approach is that it &lt;b&gt;requires&lt;/b&gt; every machine
to have this user.config file in the same place. What I want is more like what the
old &lt;a href="http://msdn2.microsoft.com/en-us/library/ms228154.aspx" target=_new&gt;file
attribute of appSettings&lt;/a&gt; provided. Unfortunately, the new tools in ASP.NET 2.0
get the connection string information from the &lt;a href="http://msdn2.microsoft.com/en-us/library/bf7sd233.aspx" target=_new&gt;connectionStrings
section&lt;/a&gt;, so using the appSettings approach is out-dated. 
&lt;p&gt;
For now, I'll use configSource, but it is a pain to have to tell each memeber of the
dev team that they need to create their very own user.config file and place it in
a certain directory, since this usage means that you wouldn't want to check user.config
into your source control system. 
&lt;p&gt;
Take a look at J.D. Meier's paper, &lt;a href="http://blogs.msdn.com/jmeier/archive/2007/04/21/how-to-reference-web-services-and-databases-during-development.aspx" target=_new&gt;How
To Reference Web Services and Databases During Development&lt;/a&gt;, for some concrete
samples on how this looks.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=581f6715-2c0c-464d-99ed-b8175209c40b" /&gt;</description>
      <comments>http://www.distribucon.com/blog/CommentView,guid,581f6715-2c0c-464d-99ed-b8175209c40b.aspx</comments>
      <category>.NET</category>
      <category>ADO.NET</category>
    </item>
    <item>
      <trackback:ping>http://www.distribucon.com/blog/Trackback.aspx?guid=43dc99a1-fca9-4428-9574-39f18ecb3c30</trackback:ping>
      <pingback:server>http://www.distribucon.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.distribucon.com/blog/PermaLink,guid,43dc99a1-fca9-4428-9574-39f18ecb3c30.aspx</pingback:target>
      <dc:creator>Dan Miser</dc:creator>
      <wfw:comment>http://www.distribucon.com/blog/CommentView,guid,43dc99a1-fca9-4428-9574-39f18ecb3c30.aspx</wfw:comment>
      <wfw:commentRss>http://www.distribucon.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=43dc99a1-fca9-4428-9574-39f18ecb3c30</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">A while back, I wrote about <a href="http://www.distribucon.com/blog/PermaLink,guid,1655.aspx" taget="_new">how
to use the Data Access Application Block (DAAB) in the Compact Framework</a>. While
this code works just fine, it turns out that <a href="http://www.codeplex.com/entlib" target="_new">Enterprise
Library 3.0</a> will support this natively. I really like the TableExists method that
they added, too. 
<p>
David Hayden wrote a couple of articles about this <a href="http://codebetter.com/blogs/david.hayden/archive/2007/02/02/Enterprise-Library-3.0-DAAB-Improvements-To-Date.aspx" target="_new">here</a> and <a href="http://davidhayden.com/blog/dave/archive/2007/01/02/SqlCeDatabaseDataAccessApplicationBlock.aspx" target="_new">here</a>.<img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=43dc99a1-fca9-4428-9574-39f18ecb3c30" /></p></body>
      <title>Enterprise Library 3.0 provides MSSQL Compact Edition support</title>
      <guid isPermaLink="false">http://www.distribucon.com/blog/PermaLink,guid,43dc99a1-fca9-4428-9574-39f18ecb3c30.aspx</guid>
      <link>http://www.distribucon.com/blog/EnterpriseLibrary30ProvidesMSSQLCompactEditionSupport.aspx</link>
      <pubDate>Wed, 21 Feb 2007 23:23:26 GMT</pubDate>
      <description>A while back, I wrote about &lt;a href="http://www.distribucon.com/blog/PermaLink,guid,1655.aspx" taget="_new"&gt;how
to use the Data Access Application Block (DAAB) in the Compact Framework&lt;/a&gt;. While
this code works just fine, it turns out that &lt;a href="http://www.codeplex.com/entlib" target="_new"&gt;Enterprise
Library 3.0&lt;/a&gt; will support this natively. I really like the TableExists method that
they added, too. 
&lt;p&gt;
David Hayden wrote a couple of articles about this &lt;a href="http://codebetter.com/blogs/david.hayden/archive/2007/02/02/Enterprise-Library-3.0-DAAB-Improvements-To-Date.aspx" target="_new"&gt;here&lt;/a&gt; and &lt;a href="http://davidhayden.com/blog/dave/archive/2007/01/02/SqlCeDatabaseDataAccessApplicationBlock.aspx" target="_new"&gt;here&lt;/a&gt;.&lt;img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=43dc99a1-fca9-4428-9574-39f18ecb3c30" /&gt;</description>
      <comments>http://www.distribucon.com/blog/CommentView,guid,43dc99a1-fca9-4428-9574-39f18ecb3c30.aspx</comments>
      <category>.NET</category>
      <category>ADO.NET</category>
      <category>Compact Framework</category>
    </item>
    <item>
      <trackback:ping>http://www.distribucon.com/blog/Trackback.aspx?guid=818592b9-7eea-478a-84c7-77ce873de426</trackback:ping>
      <pingback:server>http://www.distribucon.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.distribucon.com/blog/PermaLink,guid,818592b9-7eea-478a-84c7-77ce873de426.aspx</pingback:target>
      <dc:creator>Dan Miser</dc:creator>
      <wfw:comment>http://www.distribucon.com/blog/CommentView,guid,818592b9-7eea-478a-84c7-77ce873de426.aspx</wfw:comment>
      <wfw:commentRss>http://www.distribucon.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=818592b9-7eea-478a-84c7-77ce873de426</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">The following code assigns DateTime.MaxValue
to a parameter. When trying to run this code against the Northwind databse, it will
produce the error, "An overflow occurred while converting to datetime". 
<p></p><pre><code><!--
{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red43\green145\blue175;\red0\green0\blue255;\red163\green21\blue21;\red0\green128\blue0;}??\fs20             \cf3 SqlCeConnection\cf0  conn = \cf4 new\cf0  \cf3 SqlCeConnection\cf0 (connStr);\par ??            conn.Open();\par ??            \cf3 SqlCeCommand\cf0  cmd = \cf4 new\cf0  \cf3 SqlCeCommand\cf0 (\cf5 "select * from employees where [Hire Date] &lt; @paramDate"\cf0 , conn);\par ??\par ??            \cf3 SqlCeParameter\cf0  paramDate = cmd.CreateParameter();\par ??            paramDate.ParameterName = \cf5 "@paramDate"\cf0 ;\par ??            paramDate.DbType = \cf3 DbType\cf0 .DateTime;\par ??            paramDate.Value = \cf3 DateTime\cf0 .MaxValue\cf6 \par ??\cf0             cmd.Parameters.Add(paramDate);\par ??\par ??            \cf3 SqlCeDataAdapter\cf0  da = \cf4 new\cf0  \cf3 SqlCeDataAdapter\cf0 (cmd);\par ??            \cf3 DataTable\cf0  tbl = \cf4 new\cf0  \cf3 DataTable\cf0 ();\par ??            da.Fill(tbl);\par ??            dataGridView1.DataSource = tbl;\par ??\par ??            conn.Close();\par ??}
--><div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Consolas"><p style="MARGIN: 0px"><span style="COLOR: #2b91af">SqlCeConnection</span> conn = <span style="COLOR: blue">new</span><span style="COLOR: #2b91af">SqlCeConnection</span>(connStr);
</p><p style="MARGIN: 0px">
conn.Open();
</p><p style="MARGIN: 0px"><span style="COLOR: #2b91af">SqlCeCommand</span> cmd = <span style="COLOR: blue">new</span><span style="COLOR: #2b91af">SqlCeCommand</span>(<span style="COLOR: #a31515">"select
* from employees where [Hire Date] &lt; @paramDate"</span>, conn);
</p><p style="MARGIN: 0px">
 
</p><p style="MARGIN: 0px"><span style="COLOR: #2b91af">SqlCeParameter</span> paramDate = cmd.CreateParameter();
</p><p style="MARGIN: 0px">
paramDate.ParameterName = <span style="COLOR: #a31515">"@paramDate"</span>;
</p><p style="MARGIN: 0px">
paramDate.DbType = <span style="COLOR: #2b91af">DbType</span>.DateTime;
</p><p style="MARGIN: 0px">
paramDate.Value = <span style="COLOR: #2b91af">DateTime</span>.MaxValue;
</p><p style="MARGIN: 0px">
cmd.Parameters.Add(paramDate);
</p><p style="MARGIN: 0px">
 
</p><p style="MARGIN: 0px"><span style="COLOR: #2b91af">SqlCeDataAdapter</span> da = <span style="COLOR: blue">new</span><span style="COLOR: #2b91af">SqlCeDataAdapter</span>(cmd);
</p><p style="MARGIN: 0px"><span style="COLOR: #2b91af">DataTable</span> tbl = <span style="COLOR: blue">new</span><span style="COLOR: #2b91af">DataTable</span>();
</p><p style="MARGIN: 0px">
da.Fill(tbl);
</p><p style="MARGIN: 0px">
dataGridView1.DataSource = tbl;
</p><p style="MARGIN: 0px">
 
</p><p style="MARGIN: 0px">
conn.Close();
</p></div></code></pre><p>
Note that this fails when using MSSQL Compact Edition (MSSQLCE) under a standard WinForm
application and a Pocket PPC platform. The same code against a standard desktop MSSQL
version will work fine. 
</p><p>
The workaround is simple. Just get away from the MaxValue. Of course, this is a workaround,
so it's not perfect, but it certainly works for my needs. 
</p><pre><code> paramDate.Value = DateTime.MaxValue.AddMilliseconds(-1); </code></pre><img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=818592b9-7eea-478a-84c7-77ce873de426" /></body>
      <title>DateTime.MaxValue overflow error in MSSQL Compact Edition</title>
      <guid isPermaLink="false">http://www.distribucon.com/blog/PermaLink,guid,818592b9-7eea-478a-84c7-77ce873de426.aspx</guid>
      <link>http://www.distribucon.com/blog/DateTimeMaxValueOverflowErrorInMSSQLCompactEdition.aspx</link>
      <pubDate>Mon, 19 Feb 2007 15:37:16 GMT</pubDate>
      <description>The following code assigns DateTime.MaxValue to a parameter. When trying to run this code against the Northwind databse, it will produce the error, "An overflow occurred while converting to datetime". 
&lt;p&gt;
&lt;pre&gt;&lt;code&gt; 
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red43\green145\blue175;\red0\green0\blue255;\red163\green21\blue21;\red0\green128\blue0;}??\fs20             \cf3 SqlCeConnection\cf0  conn = \cf4 new\cf0  \cf3 SqlCeConnection\cf0 (connStr);\par ??            conn.Open();\par ??            \cf3 SqlCeCommand\cf0  cmd = \cf4 new\cf0  \cf3 SqlCeCommand\cf0 (\cf5 "select * from employees where [Hire Date] &amp;lt; @paramDate"\cf0 , conn);\par ??\par ??            \cf3 SqlCeParameter\cf0  paramDate = cmd.CreateParameter();\par ??            paramDate.ParameterName = \cf5 "@paramDate"\cf0 ;\par ??            paramDate.DbType = \cf3 DbType\cf0 .DateTime;\par ??            paramDate.Value = \cf3 DateTime\cf0 .MaxValue\cf6 \par ??\cf0             cmd.Parameters.Add(paramDate);\par ??\par ??            \cf3 SqlCeDataAdapter\cf0  da = \cf4 new\cf0  \cf3 SqlCeDataAdapter\cf0 (cmd);\par ??            \cf3 DataTable\cf0  tbl = \cf4 new\cf0  \cf3 DataTable\cf0 ();\par ??            da.Fill(tbl);\par ??            dataGridView1.DataSource = tbl;\par ??\par ??            conn.Close();\par ??}
--&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Consolas"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;SqlCeConnection&lt;/span&gt; conn = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;SqlCeConnection&lt;/span&gt;(connStr);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
conn.Open();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;SqlCeCommand&lt;/span&gt; cmd = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;SqlCeCommand&lt;/span&gt;(&lt;span style="COLOR: #a31515"&gt;"select
* from employees where [Hire Date] &amp;lt; @paramDate"&lt;/span&gt;, conn);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;SqlCeParameter&lt;/span&gt; paramDate = cmd.CreateParameter();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
paramDate.ParameterName = &lt;span style="COLOR: #a31515"&gt;"@paramDate"&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
paramDate.DbType = &lt;span style="COLOR: #2b91af"&gt;DbType&lt;/span&gt;.DateTime;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
paramDate.Value = &lt;span style="COLOR: #2b91af"&gt;DateTime&lt;/span&gt;.MaxValue;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
cmd.Parameters.Add(paramDate);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;SqlCeDataAdapter&lt;/span&gt; da = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;SqlCeDataAdapter&lt;/span&gt;(cmd);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;DataTable&lt;/span&gt; tbl = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;DataTable&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
da.Fill(tbl);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
dataGridView1.DataSource = tbl;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
conn.Close();
&lt;/p&gt;
&lt;/div&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
Note that this fails when using MSSQL Compact Edition (MSSQLCE) under a standard WinForm
application and a Pocket PPC platform. The same code against a standard desktop MSSQL
version will work fine. 
&lt;p&gt;
The workaround is simple. Just get away from the MaxValue. Of course, this is a workaround,
so it's not perfect, but it certainly works for my needs. &lt;pre&gt;&lt;code&gt; paramDate.Value
= DateTime.MaxValue.AddMilliseconds(-1); &lt;/code&gt;&lt;/pre&gt;&lt;img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=818592b9-7eea-478a-84c7-77ce873de426" /&gt;</description>
      <comments>http://www.distribucon.com/blog/CommentView,guid,818592b9-7eea-478a-84c7-77ce873de426.aspx</comments>
      <category>.NET</category>
      <category>ADO.NET</category>
    </item>
    <item>
      <trackback:ping>http://www.distribucon.com/blog/Trackback.aspx?guid=1655</trackback:ping>
      <pingback:server>http://www.distribucon.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.distribucon.com/blog/PermaLink,guid,1655.aspx</pingback:target>
      <dc:creator>Dan Miser</dc:creator>
      <wfw:comment>http://www.distribucon.com/blog/CommentView,guid,1655.aspx</wfw:comment>
      <wfw:commentRss>http://www.distribucon.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=1655</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">I've been working on a .NET Compact Framework
(CF) 2.0 application, and one thing that this applciation needed was access to a local
database on the PDA. In addition, I was hoping to leverage some of the MS Application
Blocks, specifically the Data Access Application Block, to make things easier and
more uniform for the developers. 
<p>
I came across a library that ported the <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag2/html/daab.asp" target="_new">.NET
1.1 version of the Data Access Application Block</a> to CF: <a href="http://www.businessanyplace.net/?p=daabcf" target="_new">Data
Access Application Block for .NET CF</a>. It was pretty good, but there were several
things that needed fixing for my situation, namely: removal of OpenNetCF, upgrade
to .NET CF 2.0, upgrade to Windows Mobile 5.0, and upgrade of the Northwind.sdf database
to the latest version provided by Microsoft. 
</p><p><a href="http://www.distribucon.com/download/dotnet/daabcf2.zip" target="_new">Here</a> is
my port of the original work. I'll post updates (like upgrades to <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=5A14E870-406B-4F2A-B723-97BA84AE80B5&amp;displaylang=en" target="_new">Enterprise
Library for .NET Framework 2.0, January 2006</a>) to the blog here, and my web site.
</p><img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=1655" /></body>
      <title>Data Access Application Block, CF version</title>
      <guid isPermaLink="false">http://www.distribucon.com/blog/PermaLink,guid,1655.aspx</guid>
      <link>http://www.distribucon.com/blog/DataAccessApplicationBlockCFVersion.aspx</link>
      <pubDate>Wed, 06 Dec 2006 15:50:00 GMT</pubDate>
      <description>I've been working on a .NET Compact Framework (CF) 2.0 application, and one thing that this applciation needed was access to a local database on the PDA. In addition, I was hoping to leverage some of the MS Application Blocks, specifically the Data Access Application Block, to make things easier and more uniform for the developers. 
&lt;p&gt;
I came across a library that ported the &lt;a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag2/html/daab.asp" target=_new&gt;.NET
1.1 version of the Data Access Application Block&lt;/a&gt; to CF: &lt;a href="http://www.businessanyplace.net/?p=daabcf" target=_new&gt;Data
Access Application Block for .NET CF&lt;/a&gt;. It was pretty good, but there were several
things that needed fixing for my situation, namely: removal of OpenNetCF, upgrade
to .NET CF 2.0, upgrade to Windows Mobile 5.0, and upgrade of the Northwind.sdf database
to the latest version provided by Microsoft. 
&lt;p&gt;
&lt;a href="http://www.distribucon.com/download/dotnet/daabcf2.zip" target=_new&gt;Here&lt;/a&gt; is
my port of the original work. I'll post updates (like upgrades to &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=5A14E870-406B-4F2A-B723-97BA84AE80B5&amp;amp;displaylang=en" target=_new&gt;Enterprise
Library for .NET Framework 2.0, January 2006&lt;/a&gt;) to the blog here, and my web site.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=1655" /&gt;</description>
      <comments>http://www.distribucon.com/blog/CommentView,guid,1655.aspx</comments>
      <category>ADO.NET</category>
      <category>Compact Framework</category>
    </item>
    <item>
      <trackback:ping>http://www.distribucon.com/blog/Trackback.aspx?guid=1125</trackback:ping>
      <pingback:server>http://www.distribucon.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.distribucon.com/blog/PermaLink,guid,1125.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.distribucon.com/blog/CommentView,guid,1125.aspx</wfw:comment>
      <wfw:commentRss>http://www.distribucon.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=1125</wfw:commentRss>
      <slash:comments>4</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">I have a need to allow users to build up
a connection string and store it in a config file. Pretty simple need, and I would
imagine rather standard. After all, I can't imagine any user I deploy to would have
the same connection string I do, much less the same database. As it turns out, providing
a robust piece of code to get this done will have to be all custom code. Given how
common this scenario is, I'm more than a bit disappointed that MS just punted on this
entire thing. Do they <i>really</i> expect end users to just wander around and edit
config file XML syntax by hand and get it right? Do they really think not having the
ability to do a "Test Connection" is a good idea? 
<p>
I know about the <a href="http://support.microsoft.com/default.aspx?scid=kb;EN-US;310083" target="_new">support
article from MS</a>, but that uses interop back to plain ADO. I really can't believe
they would not provide a managed code alternative that works with ADO.NET. Furthermore,
the <a href="http://msdn2.microsoft.com/en-us/library/system.data.common.dbconnectionstringbuilder.aspx" target="_new">DbConnectionStringBuilder</a> class
in ADO.NET 2.0 starts to solve the problem, but stops short, like Frank Costanza on
a drive through New York City. That class gives us some capability to build up the
connection string, but none to visually build it up, much less edit a connection string
in-place in the config file. 
</p><p>
After way more time searching around the Internet than I care to admit, I'd like to
think that I'm missing some simple link, but it looks like MS expects every single
.NET developer to implement their own Connection String Wizard from scratch. Feel
free to reply if you know of any pre-built solutions.<img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=1125" /></p></body>
      <title>Missing: Connection String Wizard</title>
      <guid isPermaLink="false">http://www.distribucon.com/blog/PermaLink,guid,1125.aspx</guid>
      <link>http://www.distribucon.com/blog/MissingConnectionStringWizard.aspx</link>
      <pubDate>Tue, 22 Aug 2006 15:14:00 GMT</pubDate>
      <description>I have a need to allow users to build up a connection string and store it in a config file. Pretty simple need, and I would imagine rather standard. After all, I can't imagine any user I deploy to would have the same connection string I do, much less the same database. As it turns out, providing a robust piece of code to get this done will have to be all custom code. Given how common this scenario is, I'm more than a bit disappointed that MS just punted on this entire thing. Do they &lt;i&gt;really&lt;/i&gt; expect
end users to just wander around and edit config file XML syntax by hand and get it
right? Do they really think not having the ability to do a "Test Connection" is a
good idea? 
&lt;p&gt;
I know about the &lt;a href="http://support.microsoft.com/default.aspx?scid=kb;EN-US;310083" target="_new"&gt;support
article from MS&lt;/a&gt;, but that uses interop back to plain ADO. I really can't believe
they would not provide a managed code alternative that works with ADO.NET. Furthermore,
the &lt;a href="http://msdn2.microsoft.com/en-us/library/system.data.common.dbconnectionstringbuilder.aspx" target="_new"&gt;DbConnectionStringBuilder&lt;/a&gt; class
in ADO.NET 2.0 starts to solve the problem, but stops short, like Frank Costanza on
a drive through New York City. That class gives us some capability to build up the
connection string, but none to visually build it up, much less edit a connection string
in-place in the config file. 
&lt;p&gt;
After way more time searching around the Internet than I care to admit, I'd like to
think that I'm missing some simple link, but it looks like MS expects every single
.NET developer to implement their own Connection String Wizard from scratch. Feel
free to reply if you know of any pre-built solutions.&lt;img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=1125" /&gt;</description>
      <comments>http://www.distribucon.com/blog/CommentView,guid,1125.aspx</comments>
      <category>ADO.NET</category>
    </item>
    <item>
      <trackback:ping>http://www.distribucon.com/blog/Trackback.aspx?guid=1097</trackback:ping>
      <pingback:server>http://www.distribucon.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.distribucon.com/blog/PermaLink,guid,1097.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.distribucon.com/blog/CommentView,guid,1097.aspx</wfw:comment>
      <wfw:commentRss>http://www.distribucon.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=1097</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">I'm using the <a href="http://msdn.microsoft.com/library/?url=/library/en-us/dnpag2/html/EntLib2.asp&quot;" target="_new">Enterprise
Library Data Access Application Block</a> in order to use a variety of different databases
on the backend without changing my code. One thing that recently came up was how to
properly use a TIMESTAMP field in MSSQL. I don't want to use SqlDbType.Timestamp,
as that refers to a specific DBMS implementation, and there is no DbType.Timestamp
at the base class level for me. The following code snippet does work, though, so use
this to get unstuck: 
<p></p><pre><code> db.AddOutParameter(cmd, "@newLastChanged", DbType.Binary, 8); </code></pre><img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=1097" /></body>
      <title>MSSQL TIMESTAMP</title>
      <guid isPermaLink="false">http://www.distribucon.com/blog/PermaLink,guid,1097.aspx</guid>
      <link>http://www.distribucon.com/blog/MSSQLTIMESTAMP.aspx</link>
      <pubDate>Mon, 31 Jul 2006 21:37:00 GMT</pubDate>
      <description>I'm using the &lt;a href=http://msdn.microsoft.com/library/?url=/library/en-us/dnpag2/html/EntLib2.asp" target="_new"&gt;Enterprise
Library Data Access Application Block&lt;/a&gt; in order to use a variety of different databases
on the backend without changing my code. One thing that recently came up was how to
properly use a TIMESTAMP field in MSSQL. I don't want to use SqlDbType.Timestamp,
as that refers to a specific DBMS implementation, and there is no DbType.Timestamp
at the base class level for me. The following code snippet does work, though, so use
this to get unstuck: 
&lt;p&gt;
&lt;pre&gt;&lt;code&gt; db.AddOutParameter(cmd, "@newLastChanged", DbType.Binary, 8); &lt;/code&gt;&lt;/pre&gt;&lt;img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=1097" /&gt;</description>
      <comments>http://www.distribucon.com/blog/CommentView,guid,1097.aspx</comments>
      <category>ADO.NET</category>
    </item>
    <item>
      <trackback:ping>http://www.distribucon.com/blog/Trackback.aspx?guid=934</trackback:ping>
      <pingback:server>http://www.distribucon.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.distribucon.com/blog/PermaLink,guid,934.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.distribucon.com/blog/CommentView,guid,934.aspx</wfw:comment>
      <wfw:commentRss>http://www.distribucon.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=934</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">This entry is a quick one, pointing out
a couple of ADO.NET related links that I came across today. 
<p><a href="http://blogs.msdn.com/cperry/archive/2006/02/06/526323.aspx" target="_new">Blog
entry showing how to add Primary Keys to GetSchema in SqlClient</a> - you could also
extend this logic to add other database-specific metadata to any ADO.NET provider 
</p><p><a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvs05/html/ddexintro.asp" target="_new">Introduction
to Visual Studio Data Designer Extensibility (DDEX)</a> - this shows how you can add/customize
functionality to the ServerExplorer in VS.NET. 
</p><p><img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=934" /></p></body>
      <title>ADO.NET links</title>
      <guid isPermaLink="false">http://www.distribucon.com/blog/PermaLink,guid,934.aspx</guid>
      <link>http://www.distribucon.com/blog/ADONETLinks.aspx</link>
      <pubDate>Mon, 20 Feb 2006 19:16:00 GMT</pubDate>
      <description>This entry is a quick one, pointing out a couple of ADO.NET related links that I came across today.
&lt;p&gt;
&lt;a href="http://blogs.msdn.com/cperry/archive/2006/02/06/526323.aspx" target="_new"&gt;Blog
entry showing how to add Primary Keys to GetSchema in SqlClient&lt;/a&gt; - you could also
extend this logic to add other database-specific metadata to any ADO.NET provider 
&lt;p&gt;
&lt;a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvs05/html/ddexintro.asp" target="_new"&gt;Introduction
to Visual Studio Data Designer Extensibility (DDEX)&lt;/a&gt; - this shows how you can add/customize
functionality to the ServerExplorer in VS.NET. 
&lt;p&gt;
&lt;img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=934" /&gt;</description>
      <comments>http://www.distribucon.com/blog/CommentView,guid,934.aspx</comments>
      <category>ADO.NET</category>
    </item>
    <item>
      <trackback:ping>http://www.distribucon.com/blog/Trackback.aspx?guid=291</trackback:ping>
      <pingback:server>http://www.distribucon.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.distribucon.com/blog/PermaLink,guid,291.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.distribucon.com/blog/CommentView,guid,291.aspx</wfw:comment>
      <wfw:commentRss>http://www.distribucon.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=291</wfw:commentRss>
      <slash:comments>3</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">Joe White took some notes on <a href="http://excastle.com/blog/archive/2004/09/13/290.aspx" target="_new">NDataStore</a>.
I will be keeping a very, very close eye on this DB. I have used <a href="http://www.borland.com/jdatastore/">JDataStore</a> in
past lives, and it was an extreme pleasure to use it. Steve Shaugnessy really knows
how to eek performance out of a DBMS. <img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=291" /></body>
      <title>NDataStore</title>
      <guid isPermaLink="false">http://www.distribucon.com/blog/PermaLink,guid,291.aspx</guid>
      <link>http://www.distribucon.com/blog/NDataStore.aspx</link>
      <pubDate>Thu, 16 Sep 2004 15:30:00 GMT</pubDate>
      <description>Joe White took some notes on &lt;a href="http://excastle.com/blog/archive/2004/09/13/290.aspx" target="_new"&gt;NDataStore&lt;/a&gt;.
I will be keeping a very, very close eye on this DB. I have used &lt;a href="http://www.borland.com/jdatastore/"&gt;JDataStore&lt;/a&gt; in
past lives, and it was an extreme pleasure to use it. Steve Shaugnessy really knows
how to eek performance out of a DBMS. &lt;img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=291" /&gt;</description>
      <comments>http://www.distribucon.com/blog/CommentView,guid,291.aspx</comments>
      <category>ADO.NET</category>
    </item>
    <item>
      <trackback:ping>http://www.distribucon.com/blog/Trackback.aspx?guid=147</trackback:ping>
      <pingback:server>http://www.distribucon.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.distribucon.com/blog/PermaLink,guid,147.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.distribucon.com/blog/CommentView,guid,147.aspx</wfw:comment>
      <wfw:commentRss>http://www.distribucon.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=147</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">The first paper on BDP is up on my <a href="http://www.distribucon.com/bdp.html">web
site</a>. This <a href="http://www.distribucon.com/bdp/BDP-DE.html">paper</a> talks
about what you need to do to get your custom BDP provider to work with the Borland
DataExplorer. I plan on adding more content to this area ASAP.<img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=147" /></body>
      <title>BDP section open at DistribuCon</title>
      <guid isPermaLink="false">http://www.distribucon.com/blog/PermaLink,guid,147.aspx</guid>
      <link>http://www.distribucon.com/blog/BDPSectionOpenAtDistribuCon.aspx</link>
      <pubDate>Sat, 06 Mar 2004 01:32:00 GMT</pubDate>
      <description>The first paper on BDP is up on my &lt;a href="http://www.distribucon.com/bdp.html"&gt;web
site&lt;/a&gt;. This &lt;a href="http://www.distribucon.com/bdp/BDP-DE.html"&gt;paper&lt;/a&gt; talks
about what you need to do to get your custom BDP provider to work with the Borland
DataExplorer. I plan on adding more content to this area ASAP.&lt;img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=147" /&gt;</description>
      <comments>http://www.distribucon.com/blog/CommentView,guid,147.aspx</comments>
      <category>ADO.NET</category>
    </item>
  </channel>
</rss>