vs2005 configure中的connection方式

在vs2005里连接数据库的字串是写在<connectionStrings>节里的,具体如下:
 
<configuration>
<connectionStrings>
    <add name="SQLCONNECTIONSTRING" connectionString="Data Source=OLDHEN;Initial Catalog=OfficeAuto;Integrated Security=True"
     providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
 
而在vs2003里,连接数据库的字串是写在<appSettings>节里的,如下所示:
 
<configuration>
<appSettings>
    <add key="SQLCONNECTIONSTRING" value="Data Source=OLDHEN;Initial Catalog=OfficeAuto;Integrated Security=True"
     providerName="System.Data.SqlClient" />
</appSettings>
</configuration>
 
注意红色字的区别。
 
在页面里调用数据库连接也因此有所区别。
在vs2005里使用下列语句来获取连接字符串:
 
string connstring = ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ToString();
 
而在vs2003里则使用下列语句来获取:
 
string connstring = ConfigurationSettrings.AppSettings
["SQLCONNECTIONSTRING"];
 
ConfigurationManager与ConfigurationSettrings同属于System.Configuration命名空间,所以要使用 using System.Configuration
  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章