如何从app.config文件中使用.NET API读取连接字符串信息?
平台是.NET 3.5
< XML版本=1.0编码=UTF-8&GT?;
<结构>
<的ConnectionStrings>
<新增的connectionString =的providerName =NAME =/>
< /的ConnectionStrings>
< /结构>
解决方案
请参阅阅读Web.Config中和的app.config和企业库DAAB设置连接字符串(在Wayback机器作为原始删除了)
ConnectionStringSettings连接= ConfigurationManager.ConnectionStrings [MyConnectionString]
字符串的connectionString = connection.ConnectionString
您可能需要添加程序集引用 System.Configuration
How to read connection string info from app.config file using .net api?
Platform is .net 3.5
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add connectionString="" providerName="" name=""/>
</connectionStrings>
</configuration>
解决方案
Please see Reading Connection Strings in Web.Config and App.Config and Enterprise Library DAAB Settings (on the Wayback Machine as the original got deleted)
ConnectionStringSettings connection = ConfigurationManager.ConnectionStrings["MyConnectionString"]
string connectionString = connection.ConnectionString
You may need to add an assembly reference to System.Configuration