在 Centos 盒子上将 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;
});
}
AddDbContext 行的值不能为 null
这是我的 appsettings.json
{ "ConnectionStrings": {
"DevDatabase": "Server=127.0.0.1;Port=3306;Database=nameOfDatabse;Uid=svcUser;Pwd=Password;"}, "Logging": {
"LogLevel": {
"Default": "Warning"} },"AllowedHosts": "*"}
我尝试修复格式希望你能阅读。
无论如何,该服务在不使用数据库时运行良好,但一旦我尝试连接到数据库,我就会得到“值不能为空”
请帮忙
最佳答案
我的 appsettings.json 是/现在为空。我相信这是一个路径错误以及我正在运行哪个 dll,但事实是。
services.AddDbContext<nameOfContextContext>(options => options.UseMySQL(add database connection string here));
和中提琴我们有赢家。我以为连接字符串错误,但只是 kestrel 找不到配置文件..
请记住,这对于生产来说可能不安全。
我计划稍后控制数据库访问的凭据
关于c# - Web-api和Kestrel访问本地MySql服务器时得到空连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55072264/