Я пытаюсь реализовать funcationality маршрутизации в MS SQL Server 2012 с использованием профайлового учебника, я создал класс С# и успешно создаю 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
Я получаю ошибку "Ошибка создания 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.
В чем причина?
После некоторых исследований я нашел решение, его проблема с перезагрузкой системы после установки.NET framework
попробуйте удалить раздел neamespace
namespace ProSQLSpatial.Ch14
{
}
Сервер sql использует пространство имен по умолчанию