views:

406

answers:

1

How can I prepare the configuration settings (App.config, maybe?) I need to use Enterprise Library Data Access Application Block in a C# console project?

Following is what I currently trying with an App.config in the console project. When I call DatabaseFactory.CreateDatabase(), it throws an exception which says:

"Configuration system failed to initialize"

<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"&gt;
        <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>
A: 

Use the Enterprise Library Configuration Tool which is integrated into Visual Studio once you install the Enterprise Library - it will ensure your configuration XML is setup correctly.

Bermo