技巧隨記:在Web.Config裡面儲存Access資料庫的串連

來源:互聯網
上載者:User
        如果你使用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("."));

這些東西,不是想出來的,是搜尋出來的。呵呵:)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.