A.Access:
1 web.config中配置
<add name="MyConnectionString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\dbwangke.mdb"/>
页面读取:
public static string connectionString = ConfigurationManager.ConnectionStrings
["MyConnectionString"].ConnectionString;
2 web.config中配置
<connectionStrings>
<add name="ConnStr" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
providerName="System.Data.OleDb"/>
<add name="ConnStr1" connectionString="App_Data/XMXCMS.mdb" providerName="System.Data.OleDb"/>
</connectionStrings>
页面读取:
ConnStr = ConfigurationManager.ConnectionStrings["ConnStr"].ToString() +
System.Web.HttpContext.Current.Server.MapPath(ConfigurationManager.ConnectionStrings
["ConnStr1"].ToString());
B.SQL Server 2000与SQL Server2005:
web.config中配置
<appSettings>
<add key="ConnectionString" value="Server=.\shuang121;database=hnzbtb;uid=sa;pwd=123456;"/>
</appSettings>
2000:<connectionStrings>
<add name="MyConnectionString" connectionString="server=.;uid=sa;pwd=sa;database=DB"/>
</connectionStrings>
2005:<connectionStrings>
<add name="ConnString" connectionString="Data Source=3F997D393A77495;Initial
Catalog=MyOffice;Persist Security Info=True;User ID=sa;Password=123456"
providerName="System.Data.SqlClient"/>
</connectionStrings>
<add name="suSoftConString" connectionString="server=.\sqlexpress;uid=sa;pwd=123456;database=puqiang;" providerName="System.Data.SqlClient"/>
页面读取:
public static readonly string connstring =
System.Configuration.ConfigurationManager.AppSettings["SQLConnString1"];
public static string connectionString = ConfigurationManager.ConnectionStrings
["MyConnectionString"].ConnectionString;