无法在MS SQL SERVER中创建程序集

时间:2014-06-23 05:50:07

标签: c# sql .net sql-server clr

我正在尝试使用prospatial教程在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 

我得到&#34;无法创建AppDomain&#34;像这样的错误:

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.

应该是什么原因?

2 个答案:

答案 0 :(得分:0)

尝试删除neamespace部分

namespace ProSQLSpatial.Ch14
{
}

sql server使用默认命名空间

答案 1 :(得分:0)

经过一些研究,我找到了解决方案, 它是.NET框架安装后系统重启的问题

相关问题