<bdo id='2BWH4'></bdo><ul id='2BWH4'></ul>

      <legend id='2BWH4'><style id='2BWH4'><dir id='2BWH4'><q id='2BWH4'></q></dir></style></legend><tfoot id='2BWH4'></tfoot>

      <small id='2BWH4'></small><noframes id='2BWH4'>

      1. <i id='2BWH4'><tr id='2BWH4'><dt id='2BWH4'><q id='2BWH4'><span id='2BWH4'><b id='2BWH4'><form id='2BWH4'><ins id='2BWH4'></ins><ul id='2BWH4'></ul><sub id='2BWH4'></sub></form><legend id='2BWH4'></legend><bdo id='2BWH4'><pre id='2BWH4'><center id='2BWH4'></center></pre></bdo></b><th id='2BWH4'></th></span></q></dt></tr></i><div id='2BWH4'><tfoot id='2BWH4'></tfoot><dl id='2BWH4'><fieldset id='2BWH4'></fieldset></dl></div>

      2. 如何在 .NET Core 中使用 PROVIDER 读取连接字符串?

        时间:2023-07-10
                  <tbody id='b3sCI'></tbody>

              • <small id='b3sCI'></small><noframes id='b3sCI'>

              • <legend id='b3sCI'><style id='b3sCI'><dir id='b3sCI'><q id='b3sCI'></q></dir></style></legend>

                  <bdo id='b3sCI'></bdo><ul id='b3sCI'></ul>
                  <tfoot id='b3sCI'></tfoot>
                  <i id='b3sCI'><tr id='b3sCI'><dt id='b3sCI'><q id='b3sCI'><span id='b3sCI'><b id='b3sCI'><form id='b3sCI'><ins id='b3sCI'></ins><ul id='b3sCI'></ul><sub id='b3sCI'></sub></form><legend id='b3sCI'></legend><bdo id='b3sCI'><pre id='b3sCI'><center id='b3sCI'></center></pre></bdo></b><th id='b3sCI'></th></span></q></dt></tr></i><div id='b3sCI'><tfoot id='b3sCI'></tfoot><dl id='b3sCI'><fieldset id='b3sCI'></fieldset></dl></div>
                  本文介绍了如何在 .NET Core 中使用 PROVIDER 读取连接字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我加了

                  .AddJsonFile("Connections.json", optional: true, reloadOnChange: true)
                  

                   public Startup(IHostingEnvironment env)
                  

                  Connections.json 包含:

                  Connections.json contains:

                  {
                    "ConnectionStrings": {
                      "DefaultConnection": "Server=(localdb)\mssqllocaldb;Database=DATABASE;Trusted_Connection=True;MultipleActiveResultSets=true",
                      "COR-W81-101": "Data Source=DATASOURCE;Initial Catalog=P61_CAFM_Basic;User Id=USERID;Password=PASSWORD;Persist Security Info=False;MultipleActiveResultSets=False;Packet Size=4096;",
                      "COR-W81-100": "Data Source=DATASOURCE;Initial Catalog=Post_PS;User Id=USERID;Password=PASSWORD;Persist Security Info=False;MultipleActiveResultSets=False;Packet Size=4096;",
                      "MSEDGEWIN10": "Data Source=DATASOURCE; Initial Catalog=COR_Basic; Persist Security Info=False;Integrated Security=true;MultipleActiveResultSets=False;Packet Size=4096;Application Name="COR_Basic"",
                  
                      "server": "Data Source=DATASOURCE; Initial Catalog=COR_Basic; Persist Security Info=False;User Id=USERID;Password=PASSWORD;MultipleActiveResultSets=False;Packet Size=4096;Application Name="COR_Basic""
                    },
                  
                  
                    "conStrings": [
                        {
                          "name": "COR-W81-101",     
                          "connectionString": "Data Source=DATASOURCE; Initial Catalog=COR_Basic; Persist Security Info=False;Integrated Security=true;MultipleActiveResultSets=False;Packet Size=4096;Application Name="COR_Basic"",
                          "providerName": "System.Data.SqlClient"
                        }
                  
                      },
                  
                      {
                        "name": "server",
                        "connectionString": "Data Source=DATASOURCE; Initial Catalog=COR_Basic; Persist Security Info=False;Integrated Security=true;MultipleActiveResultSets=False;Packet Size=4096;Application Name="COR_Basic"",
                        "providerName": "System.Data.SqlClient"
                      }
                    ],
                  
                  
                  
                    "conStringDictionary": {
                      "COR-W81-101": {
                        "connectionString": "Data Source=DATASOURCE; Initial Catalog=COR_Basic; Persist Security Info=False;Integrated Security=true;MultipleActiveResultSets=False;Packet Size=4096;Application Name="COR_Basic"",
                        "providerName": "System.Data.SqlClient"
                      },
                  
                      "server": {
                        "connectionString": "Data Source=DATASOURCE; Initial Catalog=COR_Basic; Persist Security Info=False;Integrated Security=true;MultipleActiveResultSets=False;Packet Size=4096;Application Name="COR_Basic"",
                        "providerName": "System.Data.SqlClient"
                      }
                  
                    }
                  }
                  

                  现在我想阅读连接字符串:

                  Now I wanted to read the connectionStrings:

                  public class ConnectionString
                  {
                      public string name { get; set; }
                      public string connectionString { get; set; }
                      public string providerName { get; set; }
                  }
                  

                  像这样:

                  //Microsoft.Extensions.DependencyInjection.OptionsConfigurationServiceCollectionExtensions.Configure<ConnectionString[]>(services, Configuration.GetSection("conStrings"));
                  
                  // https://stackoverflow.com/questions/31929482/retrieve-sections-from-config-json-in-asp-net-5
                  //var objectSections = Configuration.GetSection("conStringDictionary").GetChildren();
                  //foreach (var x in objectSections)
                  //{
                  //    System.Console.WriteLine(x.Key);
                  //    var cs = new ConnectionString();
                  //    ConfigurationBinder.Bind(x, cs);
                  //    System.Console.WriteLine(cs);
                  /
                  <i id='59bAe'><tr id='59bAe'><dt id='59bAe'><q id='59bAe'><span id='59bAe'><b id='59bAe'><form id='59bAe'><ins id='59bAe'></ins><ul id='59bAe'></ul><sub id='59bAe'></sub></form><legend id='59bAe'></legend><bdo id='59bAe'><pre id='59bAe'><center id='59bAe'></center></pre></bdo></b><th id='59bAe'></th></span></q></dt></tr></i><div id='59bAe'><tfoot id='59bAe'></tfoot><dl id='59bAe'><fieldset id='59bAe'></fieldset></dl></div>

                  • <small id='59bAe'></small><noframes id='59bAe'>

                    <legend id='59bAe'><style id='59bAe'><dir id='59bAe'><q id='59bAe'></q></dir></style></legend>
                    <tfoot id='59bAe'></tfoot>

                          <tbody id='59bAe'></tbody>
                        • <bdo id='59bAe'></bdo><ul id='59bAe'></ul>