.net在web.config中配置数据库连接字符串 SQL access

sql连接:
webconfig中:
<configuration>
<appSettings>
    <add key="logPath" value="c:\log.txt"/>
    <add key="ConnectionString" value="server=.;database=test;uid=sa;password=sa"/>
  </appSettings>

</configuration>
调用时:
string   conStr= System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"].ToString();
       

access连接:
webconfig中
<configuration>
<appSettings>
  <add key="oledb" value="Provider=Microsoft.Jet.OLEDB.4.0;Data source="/>
  <add key="oledp" value="~/App_Data/db.mdb;" />
</appSettings>
</configuration>
调用时:
OleDbConnection oldCon = new OleDbConnection(ConfigurationSettings.AppSettings["oledb"] + System.Web.HttpContext.Current.Server.MapPath(ConfigurationSettings.AppSettings["oledp"].Trim()));

发表评论

您的电子邮箱地址不会被公开。