首页 > 解决方案 > 无法加载 DLL 'SqlServerSpatial150.dll':找不到指定的模块。(仅在产品上)

问题描述

我不知道为什么它试图找到 v15.0,因为我明确地试图告诉它加载 v14.0。添加NuGet包时,我看到的最高版本是14.x。这在我的开发机器上完美运行,但是当部署到 prod(带有 CU8 的 win2019/sql server 2019)时,出现上述错误。

我只在调用时收到错误GetPointFromLatLong

    static DbGeography GetPointFromLatLong(double lat, double lng)
    {
        return DbGeography.FromText(string.Format("POINT({0} {1})", lng, lat), 4326);
    }


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


namespace SqlServerTypes2
{
    /// <summary>
    /// Utility methods related to CLR Types for SQL Server 
    /// </summary>
    public class Utilities
    {
        [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        private static extern IntPtr LoadLibrary(string libname);

        /// <summary>
        /// Loads the required native assemblies for the current architecture (x86 or x64)
        /// </summary>
        /// <param name="rootApplicationPath">
        /// Root path of the current application. Use Server.MapPath(".") for ASP.NET applications
        /// and AppDomain.CurrentDomain.BaseDirectory for desktop applications.
        /// </param>
        public static void LoadNativeAssemblies(string rootApplicationPath)
        {
            var nativeBinaryPath = IntPtr.Size > 4
                ? Path.Combine(rootApplicationPath, @"SqlServerTypes\x64\")
                : Path.Combine(rootApplicationPath, @"SqlServerTypes\x86\");

            LoadNativeAssembly(nativeBinaryPath, "msvcr120.dll");
            LoadNativeAssembly(nativeBinaryPath, "SqlServerSpatial140.dll");
        }

        private static void LoadNativeAssembly(string nativeBinaryPath, string assemblyName)
        {
            var path = Path.Combine(nativeBinaryPath, assemblyName);
            var ptr = LoadLibrary(path);
            if (ptr == IntPtr.Zero)
            {
                throw new Exception(string.Format(
                    "Error loading {0} (ErrorCode: {1})",
                    assemblyName,
                    Marshal.GetLastWin32Error()));
            }
        }
    }
}

标签: c#sql-server

解决方案



推荐阅读