gpt4 book ai didi

c# - Microsoft.SqlServer.Types 在 Azure 辅助角色上无法正常运行

转载 作者:行者123 更新时间:2023-11-30 14:52:08 26 4
gpt4 key购买 nike

我希望在 Azure 辅助角色中通过 EntityFramework 使用 DbGeography 与 SQL Server 数据库进行通信。据我了解,DbGeography 在后台使用 Microsoft.SqlServer.Types/SqlServerSpatial110.dll,因此为了让它在 Azure 中工作,我遵循了:

http://blogs.msdn.com/b/adonet/archive/2013/12/09/microsoft-sqlserver-types-nuget-package-spatial-on-azure.aspx并安装了 nuget 包,然后我在 WorkerRole.cs 的 OnStart 方法中指定加载 SQL Server 类型:

public override bool OnStart()
{
// Load SQL Server Types
SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);

然后我也关注了这篇博文 https://alastaira.wordpress.com/2011/08/19/spatial-applications-in-windows-azure-redux-including-denali/我明确地将 SqlServerSpatial110.dll 添加到项目中并将其设置为始终复制。

所以真正的问题是 - 部署后,一切都按预期运行。但是,如果我将 Azure Worker 角色单独放置一段时间(大约 30 分钟)并且它没有收到任何请求,则我的代码的 DbGeography 部分将不再起作用。

  • 我还需要做些什么吗?
  • 我是否将 LoadNativeAssemblies 调用放在了错误的位置(应该放在 Run() 上吗?)
  • Azure 辅助角色会被回收吗?
  • 有人曾经遇到过这种情况/设法将 DbGeography 与 Azure 辅助角色一起使用,或者对可能发生的情况有任何见解吗?

最佳答案

回复很晚了,但我在寻找解决方案时发现了你的问题。如何在 Azure Functions 中加载 SQL Server 类型。

主要问题是代码运行的路径与其他应用程序类型不同。所以你不能使用建议的:

SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~/bin")); or
SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);

在 Azure Function Run 参数中,添加 ExecutionContext 上下文,以便您检索工作文件夹。

通过向上导航一级,您可以使用此路径加载 SQL Server 类型:

public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequestMessage req, TraceWriter log, ExecutionContext context)
{
string path = context.FunctionDirectory;
string newPath = Path.GetFullPath(Path.Combine(path, @"..\"));
SqlServerTypes.Utilities.LoadNativeAssemblies(newPath);

关于c# - Microsoft.SqlServer.Types 在 Azure 辅助角色上无法正常运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32484410/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com