如何准备配置设置(可能是 App.config?)我需要在 C# 控制台项目中使用企业库数据访问应用程序块?
以下是我目前在控制台项目中尝试使用 App.config 的内容。当我调用DatabaseFactory.CreateDatabase()时,它会抛出一个异常,上面写着:
“配置系统初始化失败”
<configuration>
<dataConfiguration>
<xmlSerializerSection type="Microsoft.Practices.EnterpriseLibrary.Data.
Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<enterpriseLibrary.databaseSettings xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" defaultInstance="Northwind"
xmlns="http://www.microsoft.com/practices/enterpriselibrary/08-31-2004/data">
<databaseTypes>
<databaseType name="Sql Server" type="Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase,
Microsoft.Practices.EnterpriseLibrary.Data, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null" />
</databaseTypes>
<instances>
<instance name="Northwind" type="Sql Server" connectionString="Northwind" />
</instances>
<connectionStrings>
<connectionString name="Northwind">
<parameters>
<parameter name="Database" value="Northwind" isSensitive="false" />
<parameter name="Integrated Security" value="True" isSensitive="false" />
<parameter name="Server" value="local" isSensitive="false" />
<parameter name="User ID" value="sa" isSensitive="false" />
<parameter name="Password" value="sa1234" isSensitive="true" />
</parameters>
</connectionString>
</connectionStrings>
</enterpriseLibrary.databaseSettings>
</xmlSerializerSection>
</dataConfiguration>
</configuration>