SqlServer Spatial DataReader.GetFieldType返回null

编程入门 行业动态 更新时间:2024-10-23 16:21:44
本文介绍了SqlServer Spatial DataReader.GetFieldType返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

I have a 4.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项目兼容.

You can modify the class to be compatible with vb 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

本文发布于:2023-05-31 10:06:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/389559.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Spatial   SqlServer   DataReader   null   GetFieldType

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!