SqlServer 空间 DataReader.GetFieldType 返回 null

Geo*_*kos 4 vb.net sql-server asp.net geospatial

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

在开发机器上完美地在本地工作,但是当部署到应用程序服务器时,当我尝试在具有空间数据的表上运行查询时出现以下错误:

System.InvalidOperationException: DataReader.GetFieldType(5) returned null.
Run Code Online (Sandbox Code Playgroud)

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

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

Install-Package Microsoft.SqlServer.Types
Run Code Online (Sandbox Code Playgroud)

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

将项目重新部署到服务器后,还是不行(同样的错误)。

nuget 包中的说明说我必须将以下行添加到 applciaion_start 事件中:

SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);
Run Code Online (Sandbox Code Playgroud)

我试过这样做,但我在 SqlServerTypes 下看到一条蓝色波浪线,并在 Visual Studio 中显示错误“SqlServerTypes 未声明”。

我试过添加

Imports Microsoft.SqlServer.Types
Run Code Online (Sandbox Code Playgroud)

但没有 SqlServerTypes 命名空间或类。

Geo*_*kos 5

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

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

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

Install-Package Microsoft.SqlServer.Types
Run Code Online (Sandbox Code Playgroud)

找到以下文件:

/SqlServerTypes/Loader.cs
Run Code Online (Sandbox Code Playgroud)

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

现在您将能够从您的项目访问SqlServerTypes命名空间。