[英]Which connection string is chosen when it is specified in web.config , in IIS Default web site and in IIS application?
有一個選項可以在多個位置指定連接字符串,例如在 web.config 中,在 IIS(默認網站和應用程序本身)中,如果在所有這三個位置都指定了連接字符串,則應用程序選擇哪個連接字符串?
我對使用 IIS 8.5 運行的應用程序中的連接字符串進行了一些測試。
本地與全局 Web.Config - 每個應用程序都有本地 web.config,每個服務器都有一個全局 web.config。 全局 web.config 位於%systemroot%\\Microsoft.NET\\Framework64\\v4.0.30319\\CONFIG
對我來說。
IIS接口
沒有順序,連接字符串中有name屬性。
<connectionStrings>
<add name="RealDB" providerName="System.Data.SqlClient" connectionString="" />
<add name="NorthWind" providerName="System.Data.SqlClient" connectionString="" />
</connectionStrings>
在你想使用哪個數據庫的代碼中,你可以從 web.config 獲取它,你可以發送它或在你的數據訪問層上使用它。
var realConnection = ConfigurationManager.ConnectionStrings["RealDB"].ConnectionString;
var NortWindConnection = ConfigurationManager.ConnectionStrings["NorthWind"].ConnectionString;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.