“Spatial types and functions are not available” er

2019-03-02 19:32发布

When trying to convert a string as below

52.0986413 5.2171528

to a variable of type DbGeometry like this

Geometry = System.Data.Entity.Spatial.DbGeometry.FromText("POINT("+preometry+")");

where Geometry is of type System.Data.Entity.Spatial.DbGeometry I get the next errormessage:

Spatial types and functions are not available for this provider because the assembly 'Microsoft.SqlServer.Types' version 10 or higher could not be found.

Even though I have Microsoft.SqlServer.Types version 11.0.2 in my project. Does anybody know what the problem could be? Thanks in advance

1条回答
forever°为你锁心
2楼-- · 2019-03-02 20:01

I found the answer when I reinstalled Microsoft.SqlServer.Types.

For ASP.NET applications, add the following line of code to the Application_Start method in Global.asax.cs:

SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~/bin"));

For desktop applications, add the following line of code to run before any spatial operations are performed:

 SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);

This fixed it for me

查看更多
登录 后发表回答