title: Reading a Date field from Pervasive database causes crash
body: <p>I am trying to read some data from a Pervasive database (through a C# Console app I wrote) and whenever I reach a row that contains information on a particular date column, the program throws an exception.</p>
  
  <p>I managed to identify the problematic records:</p>
  
  <pre><code>DtTransDate        DtSystemTime           DtnLotteryDrawDate
  7/15/2013          3:01:32 AM             9/1/8226
  </code></pre>
  
  <p>As you can see, the DtnLotteryDrawDate is a weird value but I should be able to read it as it is a valid date. I am using the ADO.NET Provider for Pervasive (which by the way, indicates that there's a bug on the Pervasive driver itself):</p>
  
  <pre><code>at Pervasive.Data.SqlClient.Lna.e.ak(u )
  at Pervasive.Data.SqlClient.Lna.w.a(Int16 , Int32 , ad , f )
  at Pervasive.Data.SqlClient.Lna.e.aa(Int32 , Boolean )
  at Pervasive.Data.SqlClient.PsqlDataReader.e()
  at Pervasive.Data.SqlClient.PsqlDataReader.Read()
  </code></pre>
  
  <p>So I tried the ODBC Driver and got the same problem but a tiny better message: </p>
  
  <pre><code>at System.DateTime.DateToTicks(Int32 year, Int32 month, Int32 day)
  at System.DateTime..ctor(Int32 year, Int32 month, Int32 day, Int32 hour, Int32 minute, Int32 second, Int32 millisecond)
     at Pervasive.Data.SqlClient.Lna.u.r()
     at Pervasive.Data.SqlClient.Lna.aq.a(u )
     at Pervasive.Data.SqlClient.Lna.e.ak(u )
     at Pervasive.Data.SqlClient.Lna.w.a(Int16 , Int32 , ad , f )
     at Pervasive.Data.SqlClient.Lna.e.aa(Int32 , Boolean )
     at Pervasive.Data.SqlClient.PsqlDataReader.e()
     at Pervasive.Data.SqlClient.PsqlDataReader.Read()
  </code></pre>
  
  <p>So I tried converting the Date to a string to see if that would get rid of the issue but that didn't work. Basically, I wrote the following SQL statement:</p>
  
  <pre><code> SELECT DtTransDate ,
          TmSystemTime ,
          CONVERT(DtnLotteryDrawDate, SQL_CHAR) as DtnLotteryDrawDate
          FROM    TICKHISH
          WHERE   ( DtTransDate &gt;= { d '2013-07-15' }
  </code></pre>
  
  <p>The above SQL Statement would throw the following exception:</p>
  
  <p><code>error in row</code> and the stack trace I pasted above.</p>
  
  <p>If I DO NOT try to convert the field to string, then the Exception is more helpful:</p>
  
  <p><code>Year, Month, and Day parameters describe an un-representable DateTime.</code></p>
  
  <p>So essentially, the ADO.NET driver is trying to construct a Date passing in incorrect values for either the month or the day. Probably is passing the <code>8226</code> as either the day or the month field.</p>
  
  <p>I tried running the same SQL statement on the Pervasive Control Panel (PCC) and interestingly, the PCC program doesn't crash if I do not attempt to convert to string the date field but if I try any kind of conversion or calling a function like <code>year(DtnLotteryDrawDate)</code> immediately crashes as well.</p>
  
  <p>Any ideas on how to work around this issue? </p>
  
  <p><strong>TINY UPDATE</strong></p>
  
  <p>I was able to set up a Linked Server using SSMS and connect to the Pervasive database through the linked server. When I attempt to run this simple query:</p>
  
  <pre><code>SELECT  * FROM OPENQUERY(linked_server, 'SELECT * FROM MyTable where DtTransDate  = ''2013-07-15'' ')
  </code></pre>
  
  <p>I get this error:</p>
  
  <pre><code>OLE DB provider "MSDASQL" for linked server "linked_server" returned message "[Pervasive][ODBC Client Interface]Data truncated column 186.".
  OLE DB provider "MSDASQL" for linked server "linked_server" returned message "[Pervasive][ODBC Client Interface]Invalid date, time or timestamp value.".
  Msg 7330, Level 16, State 2, Line 3
  Cannot fetch a row from OLE DB provider "MSDASQL" for linked server "linked_server".
  </code></pre>