在做web的时候,与数据库打交道经常需要建立数据库连接。为了移植方面肯定都会用统一的连接字符串。在sqldatasource里可以这样来读取web.config的<connectionStrings> 里的字符串:

ConnectionString ="<%$ ConnectionStrings:LocalSqlServer %>"
其中web.config里的相关内容为:



connectionString ="Data Source=(local);Initial Catalog=pubs;Persist Security Info=True;User ID=sa;Password=123"
providerName ="System.Data.SqlClient" />

