使用用户机密管理数据库链接字符串

This commit is contained in:
falcon 2021-12-06 09:46:39 +08:00
parent 9767fdff20
commit f03604fa0d
3 changed files with 9 additions and 4 deletions

View File

@ -1,7 +1,7 @@
{
"db": {
"ver": "11",
"oracle": "DATA SOURCE=(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST =47.103.62.60)(PORT = 1521)))(CONNECT_DATA = (SERVICE_NAME = orcl)));PASSWORD = harmonyhis;PERSIST SECURITY INFO = True;USER ID = HARMONYHIS;Connection Lifetime = 120;Connection Timeout = 60",
"sqlserver": "Server=.\\SQLSERVER2008R2;Database=test;User ID=sa;Password=111;"
"db": { //
"ver": "",
"oracle": "",
"sqlserver": ""
}
}

View File

@ -5,11 +5,14 @@
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<UserSecretsId>44468cb2-b159-42bd-a799-b3f004be5f68</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="5.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.7" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.7" />

View File

@ -22,6 +22,7 @@ namespace Falcon.StoredProcedureRunner.Tests
System.Console.WriteLine("SqlserverTest start!");
var configurationBuilder = new ConfigurationBuilder();
configurationBuilder.AddJsonFile("AppSettings.json");
configurationBuilder.AddUserSecrets(this.GetType().Assembly);
var config = configurationBuilder.Build();
var sql = config.GetSection("db:sqlserver").Value;
var buider = new DbContextOptionsBuilder();
@ -47,6 +48,7 @@ namespace Falcon.StoredProcedureRunner.Tests
System.Console.WriteLine("OracleTest start!");
var configurationBuilder = new ConfigurationBuilder();
configurationBuilder.AddJsonFile("AppSettings.json");
configurationBuilder.AddUserSecrets(this.GetType().Assembly);
var config = configurationBuilder.Build();
var ora = config.GetSection("db:oracle").Value;
var oraVer = config.GetSection("db:ver").Value;