2
我正在編寫WsCF服務以檢索多個客戶端的數據。我有一個引用業務管理器對象的服務層。實質上,在服務調用中,我想檢索提供程序類型(我的代碼中的自定義枚舉)以及web.config中的連接字符串。IIS Express引用machine.config與項目web.config
出於某種原因,代碼無法找到我的項目web.config中的設置。我正在收集IIS Express,VS開發Web服務器正在引用machine.config。我如何覆蓋這個。這是非常令人沮喪的。正如你可以從片段中看到的設置AND連接字符串名稱存在,但代碼從來沒有拿起它。
我的代碼:
Private Sub GetDBInformation()
Dim config As System.Configuration.Configuration
config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(Nothing)
If (config.AppSettings.Settings.Count > 0) Then
Dim Setting As System.Configuration.KeyValueConfigurationElement
Setting = config.AppSettings.Settings("DB TYPE")
If Not (Setting.Value = Nothing) Then
Select Case Setting.Value
Case "SQL SERVER"
provider = ProviderType.SqlServer
Case Else
provider = ProviderType.OleDb
End Select
End If
End If
If (config.ConnectionStrings.ConnectionStrings.Count > 0) Then
connection = config.ConnectionStrings.ConnectionStrings("UMADB").ConnectionString
End If
End Sub
的Web.config:
<connectionStrings>
<add name="UMADB"
connectionString="Data Source=***********;Initial Catalog=UMA;UserID=********;Password=***********"
providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
<add key="DB TYPE" value="SQL SERVER" />
</appSettings>