SqlServer Spatial DataReader.GetFieldType returned null

南笙酒味 提交于 2019-12-10 09:23:21

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/23565095/sqlserver-spatial-datareader-getfieldtype-returned-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!