Reputation: 3936
We have an environment where each of our clients has their own database instance (with identical schemas, for all intents and purposes). We have a dashboard application where clients can login to perform CRUD operations on data in their specific database. We use a single code-first EF model for interacting with the databases. (For whatever client is being viewed, we simply pass that client's database's connection string when instantiating the DbContext
.)
However, the database instances are a mix of SQL Server 2005 and 2008. (I'm pretty sure this is the root of the problem we're seeing.)
On a particular page, we've begun to see the following error occur:
The version of SQL Server in use does not support datatype 'datetime2'.
From Googling and StackOverflowing, I've come to the conclusion that it's probably due to a misconfigured ProviderManifestToken
on the DbContext
.
However, the error is sporadic. Based on production error logs, I can view the same client for which the error occurred and perform the same CRUD operations without getting the error.
I'm at a loss.
Is it even possible to programmatically set the ProviderManifestToken
? Or maybe the default connection factory isn't properly setting it (and there's something I can do to help it along)? Or am I way off base? Any ideas?
By the way...
The entity that the error is occurring on has 2 datetime
columns, both of which are nullable (and the most recent error had null
and Jan 13, 2012 as its values for those fields, so I'm pretty sure that this answer about ensuring that the values are within datetime
's range doesn't apply.
Upvotes: 4
Views: 543
Reputation: 1
Thank you for posting this. I had the same problem with a console app that visited a SQL2008 DB than a SQL2005 DB and had the same problem. I switched it so it went SQL2005 first, than SQL2008 and the problem went away. I am also using EF code first.
Upvotes: 0
Reputation: 3936
Well, no solution yet. But we figured out a workaround for now.
If we restart the app pool, then immediately visit the client dashboard for a 2008-backed client, EF will generate and cache a mapping based on SQL Server 2008 constraints and all 2008-backed dashboards work just fine but 2005-backed dashboards fail on writes with the datetime2
error.
However, if we restart the app pool, then immediately visit a 2005-backed client dashboard, EF will generate and cache a mapping based on SQL Server 2005 constraints (which allows the model to work with both 2005 and 2008 database instances).
So, basically, our publish process now has the extra step of immediately visiting a 2005-backed dashboard.
Upvotes: 1