Question

I have a .net4.5 web application project that uses SQL server spatial datatype.

Works perfectly locally on development machine, but when deployed to application server I get the following error when trying to run queries on table with spatial data:

System.InvalidOperationException: DataReader.GetFieldType(5) returned null.

I found out that if SQLServer is not installed on the server, there is no support for spatial data types.

Therefore I installed the nuget package to my project:

Install-Package Microsoft.SqlServer.Types

This added references to Microsoft.SqlServer.Types and created a SqlServerTypes folder that contained some dlls.

After re-deploying the project to the server, it still doesn't work (same error).

The instructions from the nuget package say that I must add the following line to the applciaion_start event:

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

I have tried doing this but I am getting squiggly blue line under SqlServerTypes with the error "SqlServerTypes is not declared" in Visual Studio.

I have tried adding

Imports Microsoft.SqlServer.Types

but there is no SqlServerTypes namespace or class.

Was it helpful?

Solution

The nuget package Microsoft.SqlServer.Types is only for c# projects.

You can modify the class to be compatible with vb.net projects.

Install support into your project using:

Install-Package Microsoft.SqlServer.Types

Locate the following file:

/SqlServerTypes/Loader.cs

Convert the code in Loader.cs to vb (you can do this with an online converter) and save the file as: Loader.vb

Now you will be able to access the SqlServerTypes namespace from your project.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top