AppSettings和ConnectionStrings的區別

來源:互聯網
上載者:User

標籤:


1.<connectionStrings> 
<connectionStrings> 
<add name="ConnectionStringName" connectionString="Data Source=伺服器名;Initial Catalog=資料庫名;User ID=使用者;Password=密碼" 
providerName="System.Data.SqlClient" /> 
</connectionStrings> 

或是 

<connectionStrings> 
<add name="ConnectionStringName" connectionString="sever=伺服器名;database=資料庫名;User ID=使用者;Password=密碼" 
providerName="System.Data.SqlClient" /> 
</connectionStrings> 

在 <connectionStrings> 裡,在頁面還可以這樣引用<%$ ConnectionString:Name%>. 

2.<appSettings> 

<add key="connectionstringName" value="data source=伺服器名或IP;initial catalog=資料庫名;persist security info=False;user id=使用者;password=密碼;packet size=4096"> 
</add> 

1)AppSettings 是在2003中常用的,ConnectionStrins是2005中常用的. 
2)使用ConnectionString的好處: 
第一:可將連接字串加密,使用MS的一個加密工具即可。 
第二:可直接邦定的資料來源控制項,而不必寫代碼讀出來再賦值給控制項。 
第三:可方便的更換資料庫平台,如換為Oracle資料庫,只需修改providerName。 
3)寫在 <appSettings >中用System.Configuration.ConfigurationManager.AppSettings["name"]檢索值。 
寫在 <ConnectionStrings>中用System.Configuration.ConfigurationManager.ConnectionStrings["name"]檢索值。

AppSettings和ConnectionStrings的區別

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.