zoukankan      html  css  js  c++  java
  • 在Web.Config里面保存Access数据库的连接 (2)

    如果你使用Web.Config来保存数据库的连接那无疑是最好的形式,便于数据库的移植以及变动等一些不定性因素,便于维护就是了。可是,你可以在网络上找到保存SQL等一些数据库的连接,如果是ACCESS连接,就没有那样的方便了。不过,可以使用下面的措施来保证ACCESS的连接。

    1.在Web.Config添加:

    <appSettings>
     <add key = "ConnString"
     value = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source ={0}\\DataBase\\digestdb.config"/>
       </appSettings>

    注意,数据名字是digestdb.config(为了安全更改后缀名),放在目录DataBase下面。

    2.在数据库操作的类或者在代码里面就是如下引用了:

    private static string connString = String.Format(  System.Configuration.ConfigurationSettings.AppSettings[ "ConnString" ],
       System.Web.HttpContext.Current.Server.MapPath("."));


    3.在代码中直接使用数据库连接

    比如在一个单独的类里面:
    private static string connString = String.Format(  System.Configuration.ConfigurationSettings.AppSettings[ "ConnString" ],
       System.Web.HttpContext.Current.Server.MapPath("."));
  • 相关阅读:
    HDU 6071
    HDU 6073
    HDU 2124 Repair the Wall(贪心)
    HDU 2037 今年暑假不AC(贪心)
    HDU 1257 最少拦截系统(贪心)
    HDU 1789 Doing Homework again(贪心)
    HDU 1009 FatMouse' Trade(贪心)
    HDU 2216 Game III(BFS)
    HDU 1509 Windows Message Queue(队列)
    HDU 1081 To The Max(动态规划)
  • 原文地址:https://www.cnblogs.com/huashanlin/p/474307.html
Copyright © 2011-2022 走看看