日期:2014-05-19  浏览次数:20804 次

appconfig配置和连接问题?
我的appconfig这么些的:
<?xml   version= "1.0 "   encoding= "utf-8 "   ?>  
<configuration>  

<appSettings>  

<add   key= "DBHost "   value= "JF023\\SQLEXPRESS "   />  
<add   key= "DBName "   value= "wage "   />  
<add   key= "DBUser "   value= "sa "   />  
<add   key= "DBPass "   value= "jfis "   />  
</appSettings>  
<connectionStrings>  

</connectionStrings>  


</configuration>  
在程序中调用:
public   string   Constr()  
{  
string   dbhost   =   System.Configuration.ConfigurationManager.AppSettings[ "DBHost "];
string   dbname   =   System.Configuration.ConfigurationManager.AppSettings[ "DBName "];
string   dbuser   =   System.Configuration.ConfigurationManager.AppSettings[ "DBUser "];
string   dbpass   =   System.Configuration.ConfigurationManager.AppSettings[ "DBPass "];
string   connStr=   "server= "+dbhost+ ";database= "+   dbname+ ";uid= "+dbuser+ ";pwd= "+dbpass+ " ";  
return   connStr;
}  

为什么不行啊!

 



------解决方案--------------------
string dbhost = System.Configuration.ConfigurationManager.AppSettings[ "DBHost "];

ConfigurationManager改成ConfigurationSettings
------解决方案--------------------
同意楼上的