Error executing Databasefactory.Createdatabase() method

Asked

Viewed 633 times

5

I’m getting the following error while performing the function DatabaseFactory.CreateDatabase():

"Configuration system failed to boot"

The app.config is as follows:

<?xml version="1.0"?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
    </startup>
    <configSections>
      <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false"/>
    </configSections>
    <connectionStrings>
        <add name="store" providerName="System.Data.SqlClient" connectionString="Data Source=RL-TERMINAL\SQLEXPRESS; User ID=sa; Password=12345;Initial Catalog=store; timeout=100"/>
    </connectionStrings>
    <dataConfiguration defaultDatabase="store"/>
</configuration>

What can it be?

  • I’m not too sure if in place of <dataConfiguration> should or should not place the connection string, check out this answer: http://stackoverflow.com/questions/13993628/failing-at-database-db-databasefactory-createdatabase

  • Take a look here https://social.msdn.microsoft.com/Forums/pt-BR/7f2ffaac-f299-4669-81ef-ac35bc883dcb/appconfig-e-windows-service?forum=vscsharppt

1 answer

0

Hello. You must be using version 6 of Enterpriselibrary.

There was a change in the use of Databasefactory that forces the initial configuration of Factory.

You should set up the system like this:

<configuration>
    <configSections>
        <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data" />
    </configSections>
    <dataConfiguration defaultDatabase="base_de_dados" />
    <connectionStrings>
       <add name="base_de_dados" providerName="System.Data.SqlClient" connectionString="string_conexao" />
    </connectionStrings>
</configuration>

And in your source, for example, just do this:

var factory = new DatabaseProviderFactory();
// Crie a base de dados desta forma.
var database = factory.CreateDefault();
using (var command = database.GetSqlStringCommand("select * from tabela"))
{
    using (var dataReader = database.ExecuteReader(command))
    {
        while (dataReader.Read())
        {
        }
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.