在C#控制台项目中使用Enterprise Library DAAB

时间:2010-04-12 09:59:57

标签: c# enterprise-library console-application daab

如何准备配置设置(可能是App.config?)我需要在C#控制台项目中使用Enterprise Library Data Access Application Block?

以下是我目前正在尝试使用控制台项目中的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>

1 个答案:

答案 0 :(得分:0)

安装企业库后,使用集成到Visual Studio中的Enterprise Library Configuration Tool - 它将确保正确设置配置XML。