Increase bScale in DBPARAMBINDINFO or column scale to correct this error

Copper Contributor

I am running a C# App and trying to run a query, but it is failing with the following error:
"`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."

The column in question is of type '[datetime2](0)'. This was working with 'SQLOLEDB.1' but failing with 'MSOLEDBSQL19.1'.

  1. //connection string
  2. string serverIP = "xxxxxxxxxxxxxxxxxx";
  3. string dbname = "xxxxxxxxxxxxxxxxxx";
  4. string userid = "xxxxxxxxxxxxxxxxxxx";
  5. string password = "xxxxxxxxxxxxxxxxx";
  6. string str2 = string.Format("Provider=MSOLEDBSQL19.1;Password={0};Persist Security Info=True;User ID={1};Initial Catalog={2};Data Source={3};Initial File Name={4};Use Encryption for Data=Optional;Trust Server Certificate=False;Server SPN={5};Authentication={6};Access Token={7};Host Name In Certificate={8};", password, userid, dbname, serverIP, "\"\"", "\"\"", "\"\"", "\"\"", "\"\"");
  7. //query part
  8. string sql = @"INSERT INTO TEST_TABLE (COL1, COL2,Date) VALUES (?, ?, ?)";
  9. OleDbConnection con = null;
  10. con = new OleDbConnection(str2);
  11. con.Open();
  12. tran = con.BeginTransaction();
  13. DBHelper.ExecuteNonQuery(tran, CommandType.Text, sql,
  14. new OleDbParameter("?", "01234"),
  15. new OleDbParameter("?", "56789"),
  16. new OleDbParameter("?", DateTime.Now)
  17. );
     

     

    Table Schema:
    CREATE TABLE [dbo].[TEST_TABLE ](
    [ID] [numeric](18, 0) IDENTITY(1,1) NOT NULL,
    [COL1] [varchar](50) NOT NULL,
    [COL2] [varchar](500) NOT NULL,
    [Date] [datetime2](0) NULL)

     

    I have already tried adding the parameter "DateTypeCompatibility=80;DateTimeFormat=\"dd-mm-yyyy hh:mm:ss.fffffff\"" to connection string.
    I have also tried SQL Native Client Driver 10/11 as well.
    Edit:
    Tried: datetime2 type instead of datetime2(0)
    Tried: datetime2(7) type instead of datetime2(0)

    What could be a solution to this? My requirement is not to change the code, but to make change in either DB or connection string.
    I tried a code change -> new OleDbParameter("?", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss.fffffff")) which does work but code change
    may not be possible for some reason.

0 Replies