简体   繁体   English

ASP.NET 核心 MVC 更改连接字符串不起作用

[英]ASP.NET Core MVC Changing Connection String does not work

I'm new to ASP.Net Core and I'm in the process of moving my MS sql database from my localhost to a Linux server.我是 ASP.Net Core 的新手,正在将我的 MS sql 数据库从我的本地主机移动到 Linux 服务器。 I changed the connection string to point to the new database but the issues is that the code will not reflect the changes, it is still trying to use the old database.我更改了连接字符串以指向新数据库,但问题是代码不会反映更改,它仍在尝试使用旧数据库。 Is the connection string in the appsettings.json file the only change that I need to make or is there other changes that I need to make? appsettings.json 文件中的连接字符串是我需要进行的唯一更改,还是我需要进行其他更改? I have no idea where the code is pulling the old connection string.我不知道代码在哪里拉旧的连接字符串。

If you are using EFCore you may have this in your DbContext:如果您使用的是 EFCore,您可能在 DbContext 中有这个:

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        if (!optionsBuilder.IsConfigured)                
            optionsBuilder.UseSqlServer(
               "sqlconnstring");
    }

Might just need to update it there mate.可能只需要在那里更新它,伙计。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM