Error running Savechanges EF6

Asked

Viewed 84 times

2

Before it was working normally.

Now I face this problem when running this code:

try
{
    db.SaveChanges();
}
catch (Exception ex)
{
    //erro aqui 
}

Error message:

Exception: Spatial types and functions are not available for this Provider because the Assembly 'Microsoft.SqlServer.Types' version 10 or Higher could not be found.

Some solution?

2 answers

3


  • 1

    Danilo, your answer helped me a lot, but my site is hosted in a company and can not touch its server. So I made a small tutorial, in the answer below.

1

Alternative for those who can’t touch the server.

Install a package from Nuget:

PM> Install-Package Microsoft.SqlServer.Types -Version 14.0.1016.290

Then it goes in the file Global.asax.Cs:

using SqlServerTypes;
using System.Data.Entity.SqlServer;

protected void Application_Start()
{
    // Enables use of spatial data types
    SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~/bin"));
    SqlProviderServices.SqlServerTypesAssemblyName =
    "Microsoft.SqlServer.Types, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91";
}

And be happy

Browser other questions tagged

You are not signed in. Login or sign up in order to post.