Recently I have been playing with Entity Framework on Linux using Mono and my database server is MS SQL 2014. When I attempt to add an entity I receive the “System.Data.Entity.Core.ProviderIncompatibleException was thrown” exception and the following message was displayed:

An error occurred accessing the database. This usually means that the connection to the database failed. Check that the connection string is correct and that the appropriate DbContext constructor is being used to specify it or find it in the application’s config file. See http://go.microsoft.com/fwlink/?LinkId=386386 for information on DbContext and connections. See the inner exception for details of the failure.

So I did some further investigation online and found the following post on how to work around it:

https://entityframework.codeplex.com/discussions/538142

Create a new class called ManifestTokenResolver and save it as ManifestTokenResolver.cs in your project. Now copy and post the following code from below:

using System;
using System.Data.Entity.Infrastructure;
using System.Globalization;
using System.Data;
using System.Data.Common;

namespace ConsoleEFTest
{
	public class ManifestTokenResolver : IManifestTokenResolver
	{
		public string ResolveManifestToken(DbConnection connection)
		{
			// The simplest thing is just to return hardcoded value
			// return "2012";

			try
			{
				connection.Open();

				var majorVersion =
					Int32.Parse(connection.ServerVersion.Substring(0, 2), CultureInfo.InvariantCulture);

				if (majorVersion == 9)
				{
					return "2005";
				}

				if (majorVersion == 10)
				{
					return "2008";
				}

				return "2012";

			}
			finally 
			{
				if (connection.State == ConnectionState.Open)
				{
					connection.Close();
				}
			}
		}
	}
}

Now create another new class called Configuration and save it as Configuration.cs file in your project. Now copy the following code below and paste it into the class:

using System;
using System.Data.Entity;

namespace ConsoleEFTest
{
	public class Configuration : DbConfiguration
	{
		public Configuration()
		{
			SetManifestTokenResolver(new ManifestTokenResolver());
		}
	}
}

This class will register the ManifestTokenResolver class which will override the default one, so now we are just returning a specific version back as a string and now your exception should disappear. If you are using SQL 2014 don’t try to  change the code in the ManifestTokenResolver class to return “2014” string because I found out myself that it wont work. So stick with the code as is for now.

Currently there is bug logged at Xamarin so check the link below for further updates:

https://bugzilla.xamarin.com/show_bug.cgi?id=18534 

Shares