Hen*_*y C 3 c# sql-server entity-framework azure azure-worker-roles
我希望通过EntityFramework与Azure工作者角色中的SQL Server数据库进行通信来使用DbGeography.据我了解,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);
Run Code Online (Sandbox Code Playgroud)
然后我也按照这篇博文https://alastaira.wordpress.com/2011/08/19/spatial-applications-in-windows-azure-redux-including-denali/,在那里我明确地将SqlServerSpatial110.dll添加到项目中并设置它始终复制.
所以真正的问题是 - 在部署之后,一切都按预期工作.但是,如果我单独离开Azure Worker角色(约30分钟)并且它没有收到任何请求,则我的代码的DbGeography部分不再起作用.
回复很晚,但我在寻找解决方案时找到了你的问题.如何在Azure函数中加载SQL Server类型.
主要问题是代码运行的路径与其他应用程序类型不同.所以你不能使用建议:
SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~/bin")); or
SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);
Run Code Online (Sandbox Code Playgroud)
在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);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
699 次 |
最近记录: |