在vs2005里连接数据库的字串是写在<connectionStrings>节里的,具体如下:<configuration>
<connectionStrings>
<add name="SQLCONNECTIONSTRING" connectionString="Data Source=数据库名称;Initial Catalog=BOOK;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>而在vs2003里,连接数据库的字串是写在<appSettings>节里的,如下所示:<configuration>
<appSettings>
<add key="SQLCONNECTIONSTRING" value="Data Source=数据库名称;Initial Catalog=book;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
<connectionStrings>
<add name="SQLCONNECTIONSTRING" connectionString="Data Source=数据库名称;Initial Catalog=BOOK;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>而在vs2003里,连接数据库的字串是写在<appSettings>节里的,如下所示:<configuration>
<appSettings>
<add key="SQLCONNECTIONSTRING" value="Data Source=数据库名称;Initial Catalog=book;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
xml文件的节点改变了而已,2005是方便web.config文件加密吧!