【发布时间】:2019-12-15 07:40:00
【问题描述】:
我将 appSettings.config 更改为不再有连接字符串,因为它们现在都在 Azure Key Vault 中。我能够连接没有问题,但是现在当我尝试使用 EF 代码创建数据库时,首先使用以下方法在新的 azure db 中迁移:
添加迁移初始创建
我收到错误:
Value cannot be null.
Parameter name: connectionString
Startup.cs
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add functionality to inject IOptions<T>
services.AddOptions();
// Other configurations here such as for Blob and Notification hub
//
//
services.AddDbContext<ObContext>(opt =>
opt.UseSqlServer(Configuration["obdbqauser"]));
我的 Program.cs 看起来像这样
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((context, config) =>
{
//TODO: Seperatre dev and pro - if (context.HostingEnvironment.IsProduction())
var buildConfig = config.Build();
//Create Managed Service Identity token provider
var tokenProvider = new AzureServiceTokenProvider();
//Create the Key Vault client
var keyVaultClient = new KeyVaultClient(
new KeyVaultClient.AuthenticationCallback(
tokenProvider.KeyVaultTokenCallback));
config.AddAzureKeyVault(
$"https://{buildConfig["VaultName"]}.vault.azure.net/",
keyVaultClient,
new DefaultKeyVaultSecretManager());
})
【问题讨论】:
-
你的
Program.cs是什么样的? -
您是否尝试过将 appsettings.json 设置为复制到输出文件夹?
标签: entity-framework azure asp.net-core .net-core azure-keyvault