SqlServer Spatial DataReader.GetFieldType返回null [英] SqlServer Spatial DataReader.GetFieldType returned null

查看:132
本文介绍了SqlServer Spatial DataReader.GetFieldType返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用SQL Server空间数据类型的.net4.5 Web应用程序项目.

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.

我发现,如果服务器上未安装SQLServer,则不支持空间数据类型.

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

因此,我将nuget软件包安装到了我的项目中:

Therefore I installed the nuget package to my project:

Install-Package Microsoft.SqlServer.Types

这添加了对Microsoft.SqlServer.Types的引用,并创建了一个包含一些dll的SqlServerTypes文件夹.

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).

nuget软件包中的说明说,我必须在applciaion_start事件中添加以下行:

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);

我已经尝试过这样做,但是在Visual Studio中,我在SqlServerTypes下出现了一条弯曲的蓝线,错误为未声明SqlServerTypes".

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

我尝试添加

Imports Microsoft.SqlServer.Types

但是没有SqlServerTypes命名空间或类.

but there is no SqlServerTypes namespace or class.

推荐答案

nuget包Microsoft.SqlServer.Types仅适用于c#项目.

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

您可以修改该类以使其与vb.net项目兼容.

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

使用以下方法将支持安装到您的项目中:

Install support into your project using:

Install-Package Microsoft.SqlServer.Types

找到以下文件:

/SqlServerTypes/Loader.cs

将Loader.cs中的代码转换为vb(您可以使用在线转换器执行此操作),然后将文件另存为:Loader.vb

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

现在,您将可以从项目中访问 SqlServerTypes 命名空间.

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

这篇关于SqlServer Spatial DataReader.GetFieldType返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆