SqlMapper.cs Not Found

I am trying to run Hangfire with SQL Server 2005 which does not have datetime2 data type so I found this discussion very helpful. Unfortunately, while that fixes one problem it led immediately into another. Now I get the error: SqlMapper.cs not found. An exception of type ‘System.Data.SqlClient.SqlException’ occurred in System.Data.dll but was not handled in user code. Incorrect syntax near ‘merge’.

I found some information about the Dapper.1.38 package regarding SqlMapper.cs and obtained the code from GitHub but I get a message that the source file is different from when the module was built. It is frustrating trying to get this to work.

I’ve done more digging and found the SQL command that is causing the exception. It is this:

merge HangFire.Server as Target
using (VALUES (@id, @data, @heartbeat)) as Source (Id, Data, Heartbeat)
on Target.Id = Source.Id
when matched then
update set Data = Source.Data, LastHeartbeat = Source.Heartbeat
when not matched then
insert (Id, Data, LastHeartbeat) values (Source.Id, Source.Data, Source.Heartbeat);

I have never used the merge command before so it will take me some time to figure out what it is trying to accomplish and whether the syntax is not compatible with SQL Server 2005. Any help would be appreciated.

I have the same problem. I spent ages getting everything working on my dev machine, but when uploading to the staging server, which runs SQL Server 2005, I was getting errors.

I also changed the datetime2 to datetime, and found that hangfire servers weren’t being created. I forked the hangfire repo, and worked out how to replace the merge SQL command with corresponding INSERT and UPDATE commands. There were a few other merge commands in the codebase, so I changed those too. After deploying to the staging server again, a hangfire server started, and correctly executed the jobs I triggered.

Clicking around the hangfire dashboard caused another exception, due to a FORCESEEK hint. There were two of these in the code, so I removed them and redeployed. All seems to be working at the moment.

My forked repo is at https://github.com/harriyott/hangfire/