在MS SQL SERVER中创建程序集失败

本文关键字:创建 程序集 失败 SERVER MS SQL | 更新日期: 2023-09-27 18:09:56

我正在尝试在MS SQL Server 2012中使用预知教程实现路由功能,我创建了一个c#类并成功构建了DLL文件。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SqlServer.Server;
using Microsoft.SqlServer.Types;
namespace ProSQLSpatial.Ch14
{
public partial class UserDefinedFunctions
{
    [Microsoft.SqlServer.Server.SqlFunction]
    public static SqlGeometry GeometryTSP(SqlGeometry PlacesToVisit)
    {
        // Convert the supplied MultiPoint instance into a List<> of SqlGeometry points
        List<SqlGeometry> RemainingCities = new List<SqlGeometry>();
        // Loop and add each point to the list
        for (int i = 1; i <= PlacesToVisit.STNumGeometries(); i++)
        {
            RemainingCities.Add(PlacesToVisit.STGeometryN(i));
        }
        // Start the tour from the first city
        SqlGeometry CurrentCity = RemainingCities[0];
        // Begin the geometry
        SqlGeometryBuilder Builder = new SqlGeometryBuilder();
        Builder.SetSrid((int)PlacesToVisit.STSrid);
        Builder.BeginGeometry(OpenGisGeometryType.LineString);
        // Begin the LineString with the first point
        Builder.BeginFigure((double)CurrentCity.STX, (double)CurrentCity.STY);
        // We don't need to visit this city again
        RemainingCities.Remove(CurrentCity);
        // While there are still unvisited cities
        while (RemainingCities.Count > 0)
        {
            RemainingCities.Sort(delegate(SqlGeometry p1, SqlGeometry p2)
            { return p1.STDistance(CurrentCity).CompareTo(p2.STDistance(CurrentCity)); });
            // Move to the closest destination
            CurrentCity = RemainingCities[0];
            // Add this city to the tour route
            Builder.AddLine((double)CurrentCity.STX, (double)CurrentCity.STY);
            // Update the list of remaining cities
            RemainingCities.Remove(CurrentCity);
        }
        // End the geometry
        Builder.EndFigure();
        Builder.EndGeometry();
        // Return the constructed geometry
        return Builder.ConstructedGeometry;
    }
};
}

我还启用了CLR,当我尝试使用上面创建的DLL创建程序集时:

CREATE ASSEMBLY GeometryTSP 
FROM 'D:'Routing'my example'GeometryTSP'GeometryTSP'bin'Debug'GeometryTSP.dll' 
WITH PERMISSION_SET = EXTERNAL_ACCESS; 
GO 

我得到"Failed to create AppDomain"错误,像这样:

Msg 6517, Level 16, State 1, Line 2
Failed to create AppDomain "master.dbo[ddl].12". 
Exception has been thrown by the target of an invocation.

原因应该是什么?

在MS SQL SERVER中创建程序集失败

尝试删除neamespace部分

namespace ProSQLSpatial.Ch14
{
}

sql server使用默认命名空间

经过一番研究,我找到了解决方案。这是安装。net框架后重启系统的问题