[英]Enterprise library 4 dataconfiguration tag
我正在使用Enterprise庫進行數據訪問。 當我運行應用程序時,在CreateDatabase()語句中,我收到此異常:
用戶代碼未處理Microsoft.Practices.ObjectBuilder2.BuildFailedException消息=“當前構建操作(構建密鑰構建密鑰[Microsoft.Practices.EnterpriseLibrary.Data.Database,null])失敗:值不能為null或為空字符串。(策略類型Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfiguredObjectStrategy,index 2)“Source =”Microsoft.Practices.ObjectBuilder2“
現在,我google了一下,發現我必須放置
<dataConfiguration defaultDatabase="LocalSqlServer"/>
但我不知道在哪里。 這是正確的解決方案嗎?
另外,在安裝企業庫時我沒有看到任何連接字符串聲明? 所以,我想知道如何從web.config文件中獲取連接字符串。
在我的web.config文件的連接字符串部分中,我有:
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer" connectionString="Data Source=MSTR;Initial Catalog=USERDb;Integrated Security=true;" providerName="System.Data.SqlClient"/>
是的,您需要將dataConfiguration
部分添加到web.config。
首先,您需要將dataConfiguration添加到web.config中的ConfigurationSections列表中:
<configSections>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</configSections>
然后你需要將你的連接字符串添加到web.config(你已經這樣做了):
<connectionStrings>
<add name="LocalSqlServer" connectionString="Data Source=MSTR;Initial Catalog=USERDb;Integrated Security=true;" providerName="System.Data.SqlClient"/>
</connectionStrings>
然后,您需要將實際的dataConfiguration部分添加到web.config:
<dataConfiguration defaultDatabase="LocalSqlServer"/>
您也可以使用企業庫配置工具為您執行此操作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.