Error while executing DatabaseFactory.CreateDatabase ()

5

I'm getting the following error when executing the DatabaseFactory.CreateDatabase() function:

  

"Setup failed to initialize"

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?

    
asked by anonymous 25.12.2015 / 00:03

1 answer

0

Hello. You should be using version 6 of EnterpriseLibrary.

There has been a change in the use of the DatabaseFactory that forces Initial Factory configuration.

You should configure your 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 at 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())
        {
        }
    }
}
    
03.02.2016 / 17:54