如何通过C#中的代码从web.config获取所有连接字符串的名称?

我尝试了这个:

System.Configuration.Configuration webConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
ConnectionStringsSection x = webConfig.ConnectionStrings;
string here = x.SectionInformation.Name;

最佳答案

    foreach (ConnectionStringSettings c in System.Configuration.ConfigurationManager.ConnectionStrings)
    {
        //use c.Name
    }

关于c# - 从web.config获取多个连接字符串,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10384803/

10-10 13:15