title: Why is the SQL OLE DB Driver for SQL Server truncating seconds and fractional seconds for datetime values?
body: <p>We're introducing the OLE DB Driver for SQL Server (MSOLEDBSQL) in our legacy .NET application to support TLS 1.2. The application uses ADO.NET and has thus far been using the obsolete OLE DB Provider for SQL Server (SQLOLEDB) to connect to SQL Server instances.</p>
  <p>In short, with the new provider, a datetime object with a value representing</p>
  <pre><code>'2019-04-10 12:10:55.340'
  </code></pre>
  <p>will be truncated and then saved as</p>
  <pre><code>'2019-04-10 12:10:00.000'
  </code></pre>
  <p>Currently, the only modifications are in the connection string, where we now for MSOLEDBSQL have <code>DataTypeCompatibility=80</code> to have the driver correctly map the new data types to the ADO data types. All existing OLE DB parameters for datetime fields only define the size but not scale.</p>
  <p>This combination might seem to be a feasible part of the reason for the truncation. At least if one reads the changed behaviors when going from SQL Native Client 9.x to MSOLEDBSQL (<a href="https://docs.microsoft.com/en-us/sql/connect/oledb/applications/updating-an-application-from-sql-server-2005-native-client?view=sql-server-2017" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/sql/connect/oledb/applications/updating-an-application-from-sql-server-2005-native-client?view=sql-server-2017</a>).</p>
  <blockquote>
  <p>An application built with OLE DB Driver for SQL Server that connects to a SQL Server 2005 server will truncate seconds and fractional seconds for time portion of data sent to the server if you bind to a datetime column with a type identifier of DBTYPE_DBTIMESTAMP (OLE DB) or SQL_TIMESTAMP (ODBC) and a scale of 0.</p>
  <p>For example:</p>
  <p>Input data: 1994-08-21 21:21:36.000</p>
  <p>Inserted data: 1994-08-21 21:21:00.000</p>
  </blockquote>
  <p><strong>If the above combination is the culprit to the truncation then how can you specify a scale that is &gt; 0 without getting an OleDBException with the following message?</strong></p>
  <blockquote>
  <p>'The fractional part of the provided time value overflows the scale of the corresponding SQL Server parameter or column. Increase bScale in DBPARAMBINDINFO or column scale to correct this error.'</p>
  </blockquote>
  <p><strong>Additionally, is it somehow possible to set a default scale to be used for all OLE DB parameters of type DBTimeStamp?</strong></p>