我可以从配置文件中读取connectionstring / s但是我需要获取与连接字符串相关联的元素名称
例
<connectionStrings> <add name="LocalsqlServer" connectionString="data source=.\sqlEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.sqlClient" /> </connectionStrings>
解决方法
根据
documentation,它应该像这样工作:
ConnectionStringSettingsCollection connections = ConfigurationManager.ConnectionStrings; if (connections.Count != 0) { foreach (ConnectionStringSettings connection in connections) { string name = connection.Name; } }