question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invalid cast from 'Double' to 'DateTime' after upgrade from DMS 0.9.1 to 0.9.3

See original GitHub issue

Syncs most things then gets stuck at 91.67%: TableChangesApplyingSyncRowsArgs:Applying [SubscriptionTransactions] batch rows. State:Modified. Count:1

The exception is Invalid cast from 'Double' to 'DateTime'.

The SQLite table looks like this

CREATE TABLE [SubscriptionTransactions] (
	"ItemValue"		numeric NOT NULL CHECK (ItemValue BETWEEN -9999998.99 AND 9999999.99),
	"OrderNr"		integer NOT NULL,
	"TransactionCredit"		numeric NOT NULL CHECK (TransactionCredit BETWEEN -9999998.99 AND 9999999.99),
	"TransactionDate"		date NOT NULL COLLATE NOCASE,
	"TransactionDebit"		numeric NOT NULL CHECK (TransactionDebit BETWEEN -9999998.99 AND 9999999.99),
	"TransactionDescription"		nvarchar(20) NOT NULL COLLATE NOCASE CHECK (length(TransactionDescription) <= 20),
	"TransactionId"		integer PRIMARY KEY AUTOINCREMENT NOT NULL,
	"TransactionType"		nvarchar(15) NOT NULL COLLATE NOCASE CHECK (length(TransactionType) <= 15)

);

The SQL Server table looks like this

CREATE TABLE [dbo].[SubscriptionTransactions](
	[ItemValue] [decimal](9, 2) NOT NULL,
	[OrderNr] [int] NOT NULL,
	[TransactionCredit] [decimal](9, 2) NOT NULL,
	[TransactionDate] [date] NOT NULL,
	[TransactionDebit] [decimal](9, 2) NOT NULL,
	[TransactionDescription] [nvarchar](20) NOT NULL,
	[TransactionId] [bigint] IDENTITY(1,1) NOT NULL,
	[TransactionType] [nvarchar](15) NOT NULL,
 CONSTRAINT [PK_SubscriptionTransactions] PRIMARY KEY CLUSTERED 
(
	[TransactionId] ASC
)

The batch looks like this

"changes": {
  "t": [
    {
      "n": "SubscriptionTransactions",
      "r": [
        [
          16,
          5,
          440.0,
          2,
          0.0,
          "2022-02-20T00:00:00",
          4.38,
          "2",
          "Job"
        ]
      ]
    }
  ]
},

The stack trace is

   at Dotmim.Sync.LocalOrchestrator.<ApplyChangesAsync>d__7.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Dotmim.Sync.SyncAgent.<>c__DisplayClass53_0.<<SynchronizeAsync>b__0>d.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Dotmim.Sync.SyncAgent.<SynchronizeAsync>d__53.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Wbl.Services.DataService.<SyncAsync>d__36.MoveNext() in C:\Repos\FREE\Wbl\Services\DataService.cs:line 342

On the client

DMS.SQLite 0.9.3
DMS.Web.Client 0.9.3

On the server

DMS.SqlServer.ChangeTracking 0.9.3
DMS.Web.Server 0.9.3

This is in our development environment

In production it’s working fine using DMS 0.9.1

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Mimetiscommented, Feb 22, 2022

It’s resolved on the next version. You have to Provision the stored procedures again to be sure you have the last correct version

0reactions
Mimetiscommented, Feb 22, 2022

Yes, i’ve got it. You have your primary keys that are not ordered (I mean, usually primary keys are the first columns 😃 ) So far, the stored procedures are not generated in the correct order (order is important in v0.9.3)

In your table the column [TransactionId] is order number 7 (instead of 1) And the stored procedure is generated like this (the _getchanges stored procedure):

SELECT DISTINCT	[base].[ItemValue], 
	**[side].[TransactionId],**  <-----------------------------
	[base].[OrderNr], 
	[base].[TransactionCredit], 
	[base].[TransactionDate], 
	[base].[TransactionDebit], 
	[base].[TransactionDescription], 
	[base].[TransactionType], 
	[side].[sync_row_is_tombstone] as [sync_row_is_tombstone], 
	[side].[update_scope_id] as [sync_update_scope_id]
FROM [SubscriptionTransactions] [base]
RIGHT JOIN

And it should be generated like this:

SELECT DISTINCT	[base].[ItemValue], 
	[base].[OrderNr], 
	[base].[TransactionCredit], 
	[base].[TransactionDate], 
	[base].[TransactionDebit], 
	[base].[TransactionDescription], 
	**[side].[TransactionId],** <-----------------------------
	[base].[TransactionType], 
	[side].[sync_row_is_tombstone] as [sync_row_is_tombstone], 
	[side].[update_scope_id] as [sync_update_scope_id]
FROM [SubscriptionTransactions] [base]
RIGHT JOIN

I’m currently doing the fix for the version v0.9.4 I will commit the code in the master branch as soon as possible 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Invalid cast from double to datetime error
Hi I am getting invalid cast from double to datetime error when i run my ASP.NET MVC code. This is my code :...
Read more >
Date Value Conversion Issue - Help
i am trying to type the date using type in to activity like this : “01/01/17”. when converting i am getting error Invalid...
Read more >
DXGrid - Invalid cast from DateTime to Double
I have a special requirement where the field of type doublestores numeric data as well as DateTime Data in yyyyMMddformat. After changing the ......
Read more >
Bug listing with status RESOLVED with resolution OBSOLETE ...
... Bug:244803 - "glsa-check suggests wrong upgrade path when there is no unaffected version for the slot" status:RESOLVED resolution:OBSOLETE severity: ...
Read more >
pinentry bug fix and enhancement update
[0.9.3-1] - Update to 0.9.3 [0.9.2-1] - Update to 0.9.2 [0.9.1-1] - Update to ... rhbz#1144548 [2:0.9.4-1] - Do not clean network repos...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found