读取App.config出错?为Null值....
app.config:
<?xml version= "1.0 " encoding= "utf-8 " ?>
<configuration>
<appSettings>
<add key= "ConnectionString " value= "Data Source=KYLEYUAN;Initial Catalog=EIP;User ID=sa "/>
</appSettings>
</configuration>
=================================
class test
{
static string cnnString = System.Configuration.ConfigurationManager.AppSettings[ "ConnectionString "].ToString();
SqlConnection cnn = new SqlConnection(cnnString); ----出错...
使用坚视窗口查看:发现System.Configuration.ConfigurationManager.AppSettings[ "ConnectionString "]=null
有添加引用:System.Configuration
请问为何会这样?
------解决方案--------------------static string cnnString = System.Configuration.ConfigurationManager.AppSettings[ "ConnectionString "].ToString();
不应该这么取连接字符串
------解决方案--------------------VS 2003
<configuration>
<appSettings>
<add key= "data " value= "Provider=SQLOLEDB;Data Source=.;User ID= " ";PWD= " ";Initial Catalog=iDocument; "> </add>
</appSettings>
string sconn = ConfigurationSettings.AppSettings[ "data "];//获得连接字符串
VS 2005
<appSettings>
<add key= "data " value= "Password=sa;Persist Security Info=True;User ID=sa;Initial Catalog=YinHuaXiaoShouXiTong;Data Source=. "> </add>
</appSettings>
string sconn = ConfigurationSettings.AppSettings[ "data "];//获得连接字符串