【发布时间】:2019-03-08 23:10:54
【问题描述】:
在 Centos box 上运行 DotNet-Core 2.2 Web-Api 作为服务
我的配置服务方法中的值不能为空
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<nameOfContextContext>(options => options.UseMySQL(Configuration.GetConnectionString("DevDatabase")));
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.Configure<ForwardedHeadersOptions>(options =>
{
options.ForwardedHeaders =
ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
});
}
值不能为 null 在 AddDbContext 行
这是我的 appsettings.json
{ "ConnectionStrings": {
"DevDatabase": "Server=127.0.0.1;Port=3306;Database=nameOfDatabse;Uid=svcUser;Pwd=Password;"}, "Logging": {
"LogLevel": {
"Default": "Warning"} },"AllowedHosts": "*"}
我试图修正格式希望你能阅读。
不管怎样,服务在不使用数据库时运行良好,但当我尝试连接到数据库时,我得到 Value cannot be null
请帮忙
【问题讨论】:
-
"Null 对象是 AddDbContext 行",什么?您可以重写它以使其成为正确的陈述吗? “空对象”是矛盾的,要么是空,要么是对象
-
对不起,我会再次运行它并得到确切的错误
-
值不能为空
标签: c# mysql .net-core centos asp.net-core-webapi