有connectionString
和appSettings
之間的根本區別:
他們尋找不同的東西。在.NET 2.0及以上版本中:
A connectionString
對象是一個XML節點,它具有要設置的特定屬性;在語義上它指的是數據庫連接字符串。
例如,connectionString
如下所示:
<connectionStrings>
<clear/>
<add name="LocalSqlServer"
connectionString="Data Source=(local);Initial Catalog=aspnetdb;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
你會發現它有幾個不同的屬性:
name
connectionString
:這裏面有一個特定的字符串它需要一個安全機制Initial Catalog
(在這種情況下Integrated Security
providerName
而appSettings
僅僅是一個用戶定義的鍵值對,可以讓你...好...設置應用程序設置。它可以是任何東西:
<appSettings>
<add key="Mom" value="Your"/>
<add key="UseCache" value="True"/>
<add key="MapsKey" value="1234567890-AA"/>
<add key="SMTPServer" value="smtp.peterkellner.net"/>
</appSettings>
在許多情況下,這純粹是奇放的connectionString一個鍵值對像appSettings
(語義上和程序上)。 encrypt the connectionString when you need to會更難。
有更多的信息about this from this blog post。
如果我沒有記錯,ASP.NET 1.1不支持web.config中的「connectionStrings」部分,所以連接字符串與appSettings一起結束。你可能會遇到在1.1天內就有根源的應用程序(或者也許是開發者的習慣在2.0+項目中仍然存在)。 – 2010-06-16 17:07:24