1、Web.config 可以采用写连接条件 或 附加 ×.mdf 文件
<connectionStrings>
<add name="Sales"
providerName="System.Data.SqlClient"
connectionString= "server=myserver;database=Products;uid=<user name>;pwd=<secure password>" />
<add name="LocalSqlServer"
providerName="System.Data.SqlClient"
connectionString="server=.;database=NorthWind;Integrated Security=SSPI" />
<add name="Sql2005Express"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFileName=|DataDirectory|NorthWnd.mdf;Integrated Security=True;User Instance=true"
providerName="System.Data.SqlClient"/>
</connectionStrings>
2、×.cs 连接数据库 代码
string connectionStr = System.Configuration.ConfigurationManager.ConnectionStrings["LocalSqlServer"].ToString();
3、MSDN - 索引 - connectionStrings 可以查看web.config里数据库连接或附加设置。
ms-help://MS.MSDNQTR.v90.chs/dv_aspnetgenref/html/b6ffbb2e-a4d1-410e-8f7e-9755e92c65de.htm