gpt4 book ai didi

c# - 如果 ASP.NET 5 应用程序在 Ubuntu 上运行,它可以与 MS SQL Server 通信吗?

转载 作者:太空宇宙 更新时间:2023-11-03 23:26:23 24 4
gpt4 key购买 nike

我使用 Visual Studio 2015 中的新应用程序向导创建了一个新的 ASP.NET 5 Web 应用程序,代码在 bitbucket 上 here .在a bit of trouble with dnvm runtime setup之后,我得到了在 Ubuntu 14.04 LTS 上运行的源代码,足以加载主要的静态 html 页面,而 dnx web 为我的应用程序提供服务。但是,如果我单击“注册”链接,并尝试输入电子邮件和密码,我会在 Web UI 端收到“错误。处理您的请求时发生错误”,而在 dnx Web 端,我会收到以下消息:

error   : [Microsoft.AspNet.Diagnostics.ExceptionHandlerMiddleware] 
An unhandled exception has occurred: Could not load file or assembly
'System.Data.SqlClient, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
The system cannot find the file specified.
...
File name: 'System.Data.SqlClient'
at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyName(AssemblyName assemblyName)
at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
at Microsoft.Data.Entity.Storage.Internal.SqlServerConnection.CreateDbConnection()
at Microsoft.Data.Entity.Internal.LazyRef`1.get_Value()
at Microsoft.Data.Entity.Migrations.Internal.Migrator.Migrate(String targetMigration)
at AspNetWebApplication.Controllers.AccountController.EnsureDatabaseCreated(ApplicationDbContext context)
at AspNetWebApplication.Controllers.AccountController.<Register>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.Mvc.Controllers.ControllerActionExecutor.<CastToObject>d__8`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.Mvc.Controllers.ControllerActionInvoker.<InvokeActionAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.Mvc.Controllers.FilterActionInvoker.<InvokeActionFilterAsync>d__50.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNet.Mvc.Controllers.FilterActionInvoker.<InvokeAsync>d__41.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.Mvc.Infrastructure.MvcRouteHandler.<RouteAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.Routing.Template.TemplateRoute.<RouteAsync>d__27.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.Routing.RouteCollection.<RouteAsync>d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNet.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNet.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNet.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNet.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.Diagnostics.ExceptionHandlerMiddleware.<Invoke>d__5.MoveNext()

似乎发生了惰性初始化,并且 System.Data.SqlClient 类加载失败。

程序集存在于 ~/.dnx/packages/System.Data.SqlClient/4.0.0-beta-23409 的“dnx 缓存”中。

我假设实际问题一定是 System.Data.SqlClient 没有加载,因为它实际上与 DNX 和 Ubuntu coreclr x64 运行时环境不兼容.或者,也许我必须做其他事情来配置我的应用程序(web.config 或环境变量或其他什么?)。但在那种情况下,我会期望类加载,但无法连接。我有点期待它会尝试找到一个 MS SQL LocalDb 实例,就像它会尝试在 Windows 上找到一个实例一样,但它没有,它只是没有加载,就好像 .Net 程序集本身丢失了一样。

更新:查看像 System.Text.Encoding 这样的包很有趣。当 NuGet 获取它们时,它在其包缓存中有七个,算上七个不同的实际 DLL,按平台/操作系统,每个副本都在不同的子文件夹中,这些文件夹具有这些名称:

DNXCore50      MonoTouch10  netcore50     xamarinmac20
MonoAndroid10 net46 xamarinios10

我相信 System.Data.SqlClient 没有在其 nuget 包中提供任何 netcoreXXDNXCoreXX 变体文件夹,这使得该包实际上不可移植,尽管没有对用户的任何警告。所以类加载失败只是因为 NuGet 有一个具有该名称的包,但它不包含可以由 ubuntu 上的 coreclr x64 找到和加载的变体文件夹。

最佳答案

11 月 19 日更新

截至ASP.NET 5 RC1如果您关闭了多个事件结果集,现在应该可以在 Linux 上使用 coreclr 的 System.Data.SqlClient。请参阅 Cross-platform SQL Client here 上的发行说明.


可以让运行 Linux 的 ASP.NET 5 与 MS MSQL 通信,但可能不使用 coreclr 运行时。

System.Data.SqlClient 仅在 10 月 14 日的 corefx 中标记为完成 ,并且 beta8 于 10 月 15 日发布。我不确定它是否最终包含在 beta8 中,但您发布的错误与 beta7 的错误相同,这让我相信该库仍未包含在内。您的调查似乎也指向了这一点。

如果是这种情况,您在 Linux 上运行它的唯一选择是使用单声道运行时(与 beta7 相同)。为此,请从您的 project.json 中删除 "dnxcore50": { } 行并告诉 dnvm 以单声道而不是 coreclr 为目标。这也需要在你的 linux 机器上安装 mono(我认为是 4.1 或更高版本)。

如果你不想在盒子上安装单声道,一个mono-based aspnet 5 docker image也是一种选择。

关于c# - 如果 ASP.NET 5 应用程序在 Ubuntu 上运行,它可以与 MS SQL Server 通信吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33681040/

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